Public Group

# Little problem...

This topic is 2530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i've been trying for a way to solve this issue but i cant found how. Suppose i have 3 class defined in 3 different .h and .cpp files, and 2 of them are "sub-class" used by the main one, for example:

MainClass.h/MainClass.cpp
SubClass1.h/SubClass1.cpp
SubClass2.h/SubClass2.cpp

Ok, now let say i want to use the exact same structure in all those 3 class, for example a float3 struct, how can i do it? If i include it in one of the two sub class, the other sub-class dosen't have access to it, and if i save the structure in another file for example, the compiler complain that the structure is already defined elsewhere. What should i do so that i can use the structure in an entire project?

##### Share on other sites

Hi, i've been trying for a way to solve this issue but i cant found how. Suppose i have 3 class defined in 3 different .h and .cpp files, and 2 of them are "sub-class" used by the main one, for example:

MainClass.h/MainClass.cpp
SubClass1.h/SubClass1.cpp
SubClass2.h/SubClass2.cpp

Ok, now let say i want to use the exact same structure in all those 3 class, for example a float3 struct, how can i do it? If i include it in one of the two sub class, the other sub-class dosen't have access to it, and if i save the structure in another file for example, the compiler complain that the structure is already defined elsewhere. What should i do so that i can use the structure in an entire project?

Save it in another file (float3.h / cpp) and inside the header file write "#pragma once" as the first line, like this:
for visual c++ :

 #pragma once class float3 { //... }; 

or for other compilers:

 #ifndef FLOAT3 #define FLOAT3 class float3 { //... }; #endif 

That should work...

##### Share on other sites
Ok, thx, i think i've got it, dunno why it wasn't working before... anyway, i have another question, in my main .cpp i have a pointer declared globally like this:

CVortez3DEngine *pVortez3DEngine = NULL;

And id like to know if there is a way to access this particular pointer in any source files of the project. I've tryed extern but it dosen't seem to work.

##### Share on other sites
Nevermind, i learned how to use extern and it work now.

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004529

×