Jump to content
  • Advertisement
Sign in to follow this  
radagaisus

Something weird with Includes

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

Hey, I have a struct called hasObject in "structs.h" and a class named Object in "Object.h". The class uses the struct and vice-versa: //structs.h struct hasObject { Object* pobject; Number numOf; }; //object.h bool addHas(hasObject hasob); The problem is visual c++ 2008 express doesn't recognize Object as a class. Actually, in the editor after I write Object it recognizes it in the main function, but not if I write it just after main(). I have tried Object::Object but it still doesn't recognize. I checked hundred times that the files are included correctly. The error is this: error C2143: syntax error : missing ';' before '*' on this: Object* pobject; Any help will be appreciated

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by radagaisus
I have a struct called hasObject in "structs.h" and a class named Object in "Object.h". The class uses the struct and vice-versa:

//structs.h
struct hasObject {
Object* pobject;
Number numOf;
};

//object.h
bool addHas(hasObject hasob);
In general, you should avid circular dependencies like this wherever possible. You should be able to make this work by #including structs.h in Object.h, and providing a forward declaration of Object in structs.h.

Share this post


Link to post
Share on other sites
You may need to forward declare Object in structs.h, like this:

//structs.h
class Object; // this forward declares Object
struct hasObject
{
Object* pobject;
Number numOf;
};


This link has a nice little example.

[edit]

ninja'd++;

Share this post


Link to post
Share on other sites
Thank you!

The problem was indeed using circular declarations. I added "class Object;" and the problem was solved. Thank you for the quick reply!

I'm using struct hasObject since it stores not only a pointer to an object but also a number of how many times it can be generated, I'm writing a script language and this ensures that I can write in it, for example:

infinite is a number(+); //which means there can be infinite number of legs.
creature has #infinite leg[s]; //[] - is a comment.

And then I'll have inheritance. I could write: 'spider is a creature' and it will inherit all creature's traits and it can modify this property of it.

Thank you.

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!