Skip to main content
gamedev.net
🔒 Locked

Little problem...

Started by Vortez Sep 14, 2011 at 4:27 AM 3 replies 1.2k views
Original Post
Vortez
Vortez
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?
asm0day
asm0day

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...
Vortez
Vortez
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.
Vortez
Vortez
Nevermind, i learned how to use extern and it work now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.