header-files

How to include header files

喜你入骨 提交于 2019-12-10 12:32:29
问题 Does it matter how I import header files? I've seen double quotes as well as arrows used. #include <stdlib.h> #include "Some_Header.h" Does it matter if they're capitalized a certain way as well? Experimenting around with this, it seems neither matters, but I figure there must be a reason for tutorials doing it the way they do. Another question is, (coming from Java here), how do I access a class outside the file it was defined in? Say, I have one.cpp and two.cpp. In one.cpp: class Something

Incomplete type in C struct [closed]

此生再无相见时 提交于 2019-12-10 12:27:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I have the below project structure: file - a.h #pragma once struct best_fit_struct { void *next; size_t size; }; file - b.h #pragma once typedef struct mm_t { int type; union { struct best_fit_struct best_fit_mm; } per_mm_struct; void *memory; } mm_t; file - b.c #include "a.h" #include "b.h" on compiling b.c

When to use include guards?

感情迁移 提交于 2019-12-10 11:08:41
问题 I know that the use of include guards in header files is to prevent something from being defined twice. Using this code sample though, was completely fine: foo.c #include <stdio.h> #include <string.h> #include "bar.h" int main() { printf("%d", strlen("Test String")); somefunc("Some test string..."); return 0; } bar.h #ifndef BAR_H_INCLUDED #define BAR_H_INCLUDED void somefunc(char str[]); #endif bar.c #include <stdio.h> #include <string.h> #include "bar.h" void somefunc(char str[]) { printf(

Splitting Code into Headers/Source files

社会主义新天地 提交于 2019-12-10 10:08:45
问题 I took the following code from the examples page on Asio class tcp_connection : public boost::enable_shared_from_this<tcp_connection> { public: typedef boost::shared_ptr<tcp_connection> pointer; static pointer create(boost::asio::io_service& io_service) { return pointer(new tcp_connection(io_service)); } tcp::socket& socket() { return socket_; } void start() { message_ = make_daytime_string(); boost::asio::async_write(socket_, boost::asio::buffer(message_), boost::bind(&tcp_connection::handle

Compiler not following symbolic links in Visual Studio C++

眉间皱痕 提交于 2019-12-10 02:21:05
问题 I am using Visual Studio 2008 C++ project (Visa 32 bit). I have the following #include directive in my source code. #include <example/header.h> In my include path I specify the parent directory of 'example' , i.e. C:/.../include where the full path to the header looks like C:/.../include/example/header.h However, 'example' is a symbolic link (A '.lnk' created via file explorer 'new shortcut'). I get the following error c:...\foo.cpp(37) : fatal error C1083: Cannot open include file: 'example

instance variables in @interface; header vs implementation

℡╲_俬逩灬. 提交于 2019-12-09 14:45:59
问题 Is there any difference between declaring a private instance variable in the header vs declaring it in the implementation? in TestObj.h @interface TestObj : NSObject { int test; } @end vs in TestObj.m @interface TestObj() { int test; } @end Both seem equivalent to me, is there any actual difference between declaring an instance variable in the header vs in the implementation, if not which is preferred? The @interface within the implementation file just seems like a way to declare private

Objective c - import .m and .h file - what does it do

為{幸葍}努か 提交于 2019-12-09 04:41:26
In objective c, what actually happened when you say #import "MyClass.h"? (Is the compiler copying something for you?) In MyClass.m file, if I #import "UsefulClass.h" , this means that UsefulClass becomes available under this file and I can create object and send message to an instance of it. In myClass.m file, I have to #import "MyClass.h" , this sounds like linking my implementation file to its header (called base file?), which feels quite different from what the first one does. So does #import do two different kind of things based on circumstances? Or does it actually fall into one category

C++ circular header includes [duplicate]

痴心易碎 提交于 2019-12-08 22:10:07
问题 This question already has answers here : Resolve build errors due to circular dependency amongst classes (11 answers) Closed 4 years ago . I know that similar questions to this have been asked before but after doing my research I still have questions about circular header includes. //FooA.h #ifndef H_FOOA #define H_FOOA #include "foob.h" class FooA{ public: FooB *fooB; }; //FooB.h #ifndef H_FOOB #define H_FOOB class FooA; class FooB{ public: FooA *fooA; }; Now if I have two circular

Forward declaration / when best to include headers?

被刻印的时光 ゝ 提交于 2019-12-08 22:02:47
问题 I'm pretty clear on when I can/can't use forward declaration but I'm still not sure about one thing. Let's say I know that I have to include a header sooner or later to de-reference an object of class A. I'm not clear on whether it's more efficient to do something like.. class A; class B { A* a; void DoSomethingWithA(); }; and then in the cpp have something like.. #include "A.hpp" void B::DoSomethingWithA() { a->FunctionOfA(); } Or might I as well just include A's header in B's header file in

Getting Xcode to recognise C++ header files without the '.h' extension (OpenSceneGraph)

こ雲淡風輕ζ 提交于 2019-12-08 17:08:00
问题 OpenSceneGraph uses header files without the '.h' extension. Is there a way of getting Xcode to recognise the syntax as C++ and therefore allow me to have highlighting and jumping to definitions etc? Eg: No highlighting: 回答1: Yes. Toggle the right panel (the rightmost icon of the "View" section of the toolbar, arrow 1 in the screenshot) with your file selected. Select the document tab in the panel (arrow 2), then find "File Type" under "Identity and Type" (arrow 3). Choose "C++ header" in the