Jump to content
  • Advertisement
Sign in to follow this  
Vortez

Little problem...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!