Jump to content
  • Advertisement
Sign in to follow this  
Kryodus

Strange behaviour with inheritance and multiple files

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

After thinking and thinking for hours on why the hell I was getting strange errors, and comparing with sample code found on the internet ive figured out how to solve my problem I was about to post on. My new question is why the hell do I need to do this ? If I have multiple files, lets say a main.cpp, person.cpp and a student.cpp where student is a subclass of person and main is a file containing the main method acesssing person.cpp and student.cpp I need to put #ifndef somerandomname #define somerandomname (block of code containng class infomraiton) #endif in both student.cpp and person.cpp or I get the error "redefinition of a class name person " insanely frustrated cause it took me forever to figure out, and I dont understand why I need to do this. If the wise gurus of this forum who have saved my brain hours of frustrating useless thinking could shed some light on this, I would be forever in their debt (again :))

Share this post


Link to post
Share on other sites
Advertisement
Include guards are simply a way of getting out of an infinite loop of reference. Put simply, the compiler/linker can tell two uses of the same include apart.

(I.e without it you would get A=>B=>A... )

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!