Jump to content

  • Log In with Google      Sign In   
  • Create Account

Quick help req, Passing a inherited class from base class issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 1246

Like
0Likes
Like

Posted 22 December 2013 - 02:17 PM

Hello.

I got brain freeze or long week to say it better and i cant just remember how did i do the following:

class tire
{
...
};
 
class car : public tire
{
...
};
 
void RemoveTire(tire* TheTire)
{
...
}
 
int main
{
car objCar;
RemoveTire(objCar);//This line right here i just cant get it intro my head how did i do it like that
}

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 Lactose!   GDNet+   -  Reputation: 3827

Like
2Likes
Like

Posted 22 December 2013 - 02:25 PM

 

Hello.

I got brain freeze or long week to say it better and i cant just remember how did i do the following:

class tire
{
...
};
 
class car : public tire
{
...
};
 
void RemoveTire(tire* TheTire)
{
...
}
 
int main
{
car objCar;
RemoveTire(objCar);//This line right here i just cant get it intro my head how did i do it like that
}

Your RemoveTire function takes a pointer to a tire. You need to pass the address of objCar for it to compile.

 

Edit: That said, that class inheritance doesn't make a lot of sense to me. A car is a sub-class of tire?


Edited by CoreLactose, 22 December 2013 - 02:28 PM.


#3 Paradigm Shifter   Crossbones+   -  Reputation: 5435

Like
6Likes
Like

Posted 22 December 2013 - 02:26 PM

RemoveTire(&objCar);

 

 

You need more than quick help though. This line:

 

class car : public tire
 

says a car IS A tire. And anything that applies to a tire should also apply to a car. This is clearly wrong.

 

EDIT: You want composition instead, a car HAS A tire (or more than one).


Edited by Paradigm Shifter, 22 December 2013 - 02:28 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#4 BaneTrapper   Members   -  Reputation: 1246

Like
0Likes
Like

Posted 22 December 2013 - 07:45 PM

Well i changed the subjest in order to get a easy answer and not type walls of text...

I am not using that in the sense you think i do not need a car inheriting from tire at all...

Function that has X as parameter, Object that has X inherited, how to pass from the Object intor Function the parameter X...

I dig thrue my project, but i cant find it, also cant remember sad.png .

 

EDIT:
I rememberd, thanks on attempts.


Edited by BaneTrapper, 22 December 2013 - 08:33 PM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS