Simple c++ ques: how to define a struct over mult files?
-
Hi, Just a basic question: How do you define a struct so that it's visible over multiple files? For example, for a function I know you would create a header file and include the forward declaration, there... while implementing the function in a .cpp file. Is there a similar forward declaration for a struct, or do I have to create a namespace ? Thanks - @LG
-
Hi, Just a basic question: How do you define a struct so that it's visible over multiple files? For example, for a function I know you would create a header file and include the forward declaration, there... while implementing the function in a .cpp file. Is there a similar forward declaration for a struct, or do I have to create a namespace ? Thanks - @LG
-
I think this is as straight-forward as it appears ... define the structure in a header file and include the .h in any source file that needs to reference the type Judy
Hi Judy, Thanks for your reply. The trouble I was having with that approach is that the compiler would give me an error stating that I was multiply defining the struct in question. So, poking around on the net a bit I found this great page on the preprocessor and "header file etiquette"... http://www.codeguru.com/cpp/tic/tic0056.shtml and it explained how to use an "include guard" (#ifdef) to protect from the problem that I was having. -@LG
-
Hi Judy, Thanks for your reply. The trouble I was having with that approach is that the compiler would give me an error stating that I was multiply defining the struct in question. So, poking around on the net a bit I found this great page on the preprocessor and "header file etiquette"... http://www.codeguru.com/cpp/tic/tic0056.shtml and it explained how to use an "include guard" (#ifdef) to protect from the problem that I was having. -@LG