header-files

Should '#include' and 'using' statements be repeated in both header and implementation files (C++)?

岁酱吖の 提交于 2019-12-04 05:19:48
I'm fairly new to C++, but my understanding is that a #include statement will essentially just dump the contents of the #included file into the location of that statement. This means that if I have a number of '#include' and 'using' statements in my header file, my implementation file can just #include the header file, and the compiler won't mind if I don't repeat the other statements. What about people though? My main concern is that if I don't repeat the '#include', 'using', and also 'typedef' (now that I think of it) statements, it takes that information away from the file in which it's

What is the significance of a .h file?

依然范特西╮ 提交于 2019-12-04 05:19:24
I know that .h file is supposed to have: class declarations, function prototypes, and extern variables (for global variables) But is there some significance of making it a .h file? I tried renaming my .h file to a .c file and it still works. We can name our file to be anything, but we choose to name it as a .h file. Am I correct? The use of .h to name header files is just a convention. You will also see (probably on Unix-like platforms): .hpp (the Boost library uses these) .hxx (looks like h++ with the + signs tilted - cute, huh?) .H (Unix is case sensitive so you can distinguish these from .h

Xcode cannot find #Include<> header

瘦欲@ 提交于 2019-12-04 05:05:11
I'm trying to get Xcode to import the header file for Irrlicht. #include <irrlicht.h> It says "Irrlicht.h. No such file or directory". Yes Irrlicht.h with a capital I, even though the #include is lowercase. Anyway I added "/lib/irrlicht-1.6/include" in the header search paths for the Xcode project, yet it still doesn't find it. The only thing I've tried that does work is: #include "/lib/irrlicht-1.6/include/irrlicht.h" This is a bit ridiculous though, #include should work, I don't understand why it isn't working. Update (here are more details on the error): /lib/PAL/pal_benchmark/palBenchmark

class foo; in header file

时光怂恿深爱的人放手 提交于 2019-12-04 04:02:11
问题 Is some one able to explain why header files have something like this? class foo; // This here? class bar { bar(); }; Do you need an include statement when using this? Thanks. 回答1: The first class foo; is called a forward declaration of the class foo. It simply lets the compiler know that it exists and that it names a class. This makes foo what is called an "incomplete type" (unless the full declaration of foo has already been seen). With an incomplete type, you can declare pointers of that

Header files linked to from header file not found.

江枫思渺然 提交于 2019-12-04 03:31:36
问题 I have a problem with Nvidia's OpenCl/Cuda framework, but I think it is a gcc linking issue. The opencl_hello_world.c example file uses following header file: #include "../OpenCL/common/inc/CL/opencl.h" with opencl.h using these header files: #include <../OpenCL/common/inc/CL/cl.h> #include <../OpenCL/common/inc/CL/cl_gl.h> #include <../OpenCL/common/inc/CL/cl_gl_ext.h> #include <../OpenCL/common/inc/CL/cl_ext.h> So all the header files are in the same folder. When I then compile with gcc

Cost of Including Header Files in Objective-C

a 夏天 提交于 2019-12-04 03:03:40
This may seem like a really stupid question, but what is the cost of including (actually, calling #import ) a header file in Objective-C? I get tired of constantly including the same headers in various locations, so I decided to simply create a GlobalReferences.h file that includes several commonly-referenced headers. Is there any appreciable cost for including references to other files if they aren't even used? My gut tells me "no" as it seems like the linker is just made aware of other files when using #import , but I wasn't sure if special considerations need to be taken for iPhone

instance variables in @interface; header vs implementation

耗尽温柔 提交于 2019-12-04 00:57:15
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 properties, does it have any other purpose outside that? The preference is generally to place private

undefined reference to <function name>

老子叫甜甜 提交于 2019-12-03 23:04:06
I have this simple test file: #include "stack.h" int main() { Stack* stck = init_stack(); return 0; } and stack.h is defined as follows: #ifndef STACK_H #define STACK_H #define EMPTY_STACK -1 typedef struct stack { char ch; struct stack* prev; } Stack; extern Stack* init_stack(); extern char pop(Stack*); extern void push(Stack*, char); #endif These two files are in the same directory. But when I do gcc .. to build it, I keep getting the error below: $ ls stack.c stack.h teststack.c $ gcc -o testit teststack.c /tmp/ccdUD3B7.o: In function `main': teststack.c:(.text+0xe): undefined reference to

Install ruby headers with rvm

点点圈 提交于 2019-12-03 17:23:14
Travis CI uses RVM to provide Ruby, but it doen't seem to contain the headers: $ find /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux/zlib.so /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux/dl.so /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux/syck.so /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux/socket.so /home/vagrant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux/dbm.so

How to use extern cuda device variables

我怕爱的太早我们不能终老 提交于 2019-12-03 17:17:22
I need to write the code into several .cu files. But where should I define the device variables which are use for many .cu files. An example File common.h __device__ int x; File A.cu __global__ void a() File B.cu __global__ void b() a(),b() both use x. what should I do? In C language, I should write something like extern device int x; Then I define device int x in another place. But in CUDA I can not do it. If I do, it tells me ‘..........’ previously declared here EDIT : @talonmies was right (as usual). So I've deleted my comment about CUDA 4.1 Furthermore the compiling commands I gave were