Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Recursive #including

This topic is 4210 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

I have two classes, classA and classB. in two header files classA.h and classB.h including them within each others header files causes problems (from what i can see, since each of them has a #pragma once at the start, it won't get included the second time), how can i get around this without restructuring the code?

Share this post


Link to post
Share on other sites
Advertisement
Well you can use defines as in:


#ifndef __Some_Header_h__
#define __Some_Header_h__

Header code
Header code
Header code

#endif //__Some_Header_h__




You can also read this nice article for more info.

Mikle

Share this post


Link to post
Share on other sites
Thanks for the replies. I read that article and tried prototyping class B in classA.h, but i still have problems. I think it's cause a member function fo class B is being called...

classA.h

class B; //define class B here to allow it to be referenced in class A

class A{}; //prototype of class A

..

and then in classA.cpp

void classA::DoStuff(B* someB)
{
someB->DoThings();
}


gives me...

error C2027: use of undefined type 'classB'
...GameManager.h(10) : see declaration of 'classB'

Share this post


Link to post
Share on other sites
You still need to #include b.h somewhere, otherwise you cannot use the details of the class. Just include it in the .cpp file, just after including a.h.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mikle3
Well you can use defines as in:

*** Source Snippet Removed ***

You can also read this nice article for more info.

Mikle

Just to correct the quoted post, the standard says:
Quote:
17.4.3.1.2 Global names [lib.global.names]
1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter
(2.11) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global
namespace.

Share this post


Link to post
Share on other sites
Quote:
Original post by CmpDev
Quote:
Original post by Mikle3
Well you can use defines as in:

*** Source Snippet Removed ***

You can also read this nice article for more info.

Mikle

Just to correct the quoted post, the standard says:
Quote:
17.4.3.1.2 Global names [lib.global.names]
1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter
(2.11) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global
namespace.



Rules are made to be broken... I know that __ is for system stuff and _ is for private members, but hell, no need to be so tight about it...It's a define that's supposed to be unique. I think even MSVC provides you with a unique identifier starting in __...

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!