• Advertisement
Sign in to follow this  

the overloaded function that just wouldn't

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

I have a class called Ship and a child class called ShipAI. The update() function in ShipAI is supposed to overload the update() function is ship, but its not. Here's a bit of the code from the header file.
class Ship {
(snip)
public:
	
	Ship();
	
	//this is called every frame by WorldMgr
	void update(Real timeSinceLastFrame);
(snip)
};




class ShipAI: public Ship {
(snip)
public:
	ShipAI();
	void update(Real timeSinceLastFrame);
};

I have a std::vector of pointers to Ship and each frame is cycles through that list and calls the update() function. Here's the code:
vector<Ship*>::iterator i;
for (i=mShips.begin(); i!=mShips.end(); i++){
	//cout << "updating ship" << (*i)->getShipID() << endl;
	(*i)->update(evt.timeSinceLastFrame);
}
The list includes Ship's and ShipAI's. I would have thought that when it came across a ShipAI class it would call ShipAI::update() instead of Ship::update(), but it doesn't. I have cout traces in the ShipAI constructor and the Ship constructor and in ShipAI::update(). On world creation I manually spawn one Ship class and one ShipAI class. I see the output of Ship twice and ShipAI once so I know it's being created properly. Am I an idiot or whats going on? Thx.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by TheMoebius
The update() function in ShipAI is supposed to overload the update() function is ship

You mean "overwrite", right?

Quote:

void update(Real timeSinceLastFrame);

Make the method virtual, then it should work.

Share this post


Link to post
Share on other sites
I knew it had to be me. I've been working with Java too much lately.

Thanks for the coffee. (no pun intended?)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement