Jump to content
  • Advertisement
Sign in to follow this  
NcatDesigner

inheritance redefinition problem

This topic is 4156 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 people!!!!! How can I avoid inheritance redefinition? Let's imagine I've got the vehicle class, and to "sons", motorbike and car. I thought I could create vehicles from my main class just including vehicle.h, but I can. If I include vehicle.h I can't create a motorbike because it doesn't recognize it as a class/object/type. And I include motorbike.h I can create as motorbikes as I want, but I can't include car.h because of redefinition. The reason is motorbike includes have methods from vehicle.h as car.h I hope you have understood this, Anyone can help me please?

Share this post


Link to post
Share on other sites
Advertisement
I don't undestand one thing,

If I create:

Vehicle v;

why I can say after that:

v = car(supposed_attributes); ?????

Can anyone help me.

Refering to the redefinition part, I added in ALL the headers #ifndef, #define, #endif (I've read the article above -> thanks) And now I only have this two new erros:

c2011 class 'type' redefinition vehicle
c2504 base class undefined car

HELP

I've readed this but I undestood nothing

http://www.gamedev.net/community/forums/topic.asp?topic_id=296842&whichpage=1��

Share this post


Link to post
Share on other sites
#pragma once did it!!!!!!!

I'm feeling so stupid right know

Anyone has any suggestion about my other question?

Can I create a vehicle ( Vehicle v) and then declare it as motorbike for example?

if I put Vehicle v; I must include Vehicle.h else if I want to create a motorbike I must include Motorbike.h, But I can create a Vehicle and then declare it as motorbike:

Vehicle v;
v= motorbike(...);

Share this post


Link to post
Share on other sites
I don't think it's possible, but you're better off instantializing a motorbike first anyway, rather than type-setting a vehicle as another class. If it's a matter of giving your players options, don't instantialize anything until they've made their choice.

Another thing that may help is to put your motorbike class definition and functions in the same header/cpp file as your vehicle definitions and functions, since motorbike is simply an derived vehicle class (or did you change that?). It will cut down on your #includes, if nothing more, and reduce the possibility of you forgetting and causing errors.

Share this post


Link to post
Share on other sites
Quote:
Original post by NcatDesigner
I'm not sure but I'm refering to some kind of polymorphism


Polymorphism is achieved through pointers or references. Examples:

Vehicle* ptv1 = new motorbike(); // Created on the heap (remember to delete)

// or the preferred way...

void someFunction(Vehicle& v) // a motorbike can be passed to this function
{
v.startEngine(); // overriden versions of these functions will be used if available
v.drive();
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!