|
|
Re: Find_My_Vehicle [message #456960 is a reply to message #456821] |
Thu, 06 October 2011 07:10 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma: 0
|
General (5 Stars) |
|
|
VehicleGameObject pVehicleObj = Find_My_Vehicle();
GameObject* pObject = dynamic_cast<GameObject*>(pVehicleObj);
Or...
GameObject* pObject = dynamic_cast<GameObject*>(Find_My_Vehicle());
Or...
GameObject* pObject = (GameObject*)Find_My_Vehicle();
(PS: If you didn't already figure it out, VehicleGameObject *is* a GameObject, since it's a derived class)
(PPS: Yes, I know dynamic casting a subclass to its superclass is redundant since it's always going to succeed, just illustrating my point )
[Updated on: Thu, 06 October 2011 07:14] Report message to a moderator
|
|
|
Re: Find_My_Vehicle [message #457022 is a reply to message #456821] |
Thu, 06 October 2011 17:28 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
ok that works although i dont understand how it works i gues i understand it somehow on some way XD im just a nooby in programmin
Owner of kambot TT server
kambot.freeforums.org
|
|
|
Re: Find_My_Vehicle [message #457045 is a reply to message #456821] |
Fri, 07 October 2011 00:27 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
VehicleGameObject is derived from GameObject.
This means VehicleGameObject is everything GameObject is +more.
The code for this would be
class VehicleGameObject : public GameObject{...};
*note: In the scripts.dll source, there might be an inheritance in between or multiple inheritance. I did not check this code so it may look a bit different in the real source. This does however reflect how VehicleGameObject is a GameObject
You can ofcourse have this stacked
class X{...};
//Y is X +more
class Y : public X{...};
//Z is Y +more
class Z : public Y{...};
As Z derives from Y, and Y from X, Z is also an X.
Or multiple
class A{...};
class B{...};
class C : public A, B{...};
C is both an A and B, BUT A is not a B and B is not an A in this case.
http://www.cprogramming.com/tutorial/lesson20.html
Then you also get things like access modifiers and the virtual keyword that all affect inheritance behavior, but you can search that up when you need it
[Updated on: Fri, 07 October 2011 00:37] Report message to a moderator
|
|
|
|