Name: Anonymous 2008-03-26 1:57
alright, i need c++ help again, you guys delivered for me the other night, heres hoping you'll help again.
the context is a space sim. I have a class called ship which holds data members for a 3d position, a throttle, speed, a name and an engine.
now i have a method called move ship which calculates the ships speed based on the throttle integer, the max speed and the acceleration factor and adds that value to the ships current position. The problem is the members accel and max_spd are stored in the engine class, this isn't a problem except i want to abstract the ship and the engine class so i can call child classes of both shp and engine so i can in essence reuse that code to make as many ship types as I want out of the same two peices of code...
so my first try was to simply make a ship class with a data member function that calls the engine class. i.e.
class ship{
Engine m_engine
}
so far so good until i try to derive that out like so
sSpartan : public ship
{
eng_mk1 m_engine;
]
eng_mk1 is a class derivation of Engine, it always initilized the Engine m_engine part in the base class constructor, and eng_mk1 object is never created
I'm pretty sure im going to have to rely on virtual functions... I get the idea, but no the syntax. halp plz?
the context is a space sim. I have a class called ship which holds data members for a 3d position, a throttle, speed, a name and an engine.
now i have a method called move ship which calculates the ships speed based on the throttle integer, the max speed and the acceleration factor and adds that value to the ships current position. The problem is the members accel and max_spd are stored in the engine class, this isn't a problem except i want to abstract the ship and the engine class so i can call child classes of both shp and engine so i can in essence reuse that code to make as many ship types as I want out of the same two peices of code...
so my first try was to simply make a ship class with a data member function that calls the engine class. i.e.
class ship{
Engine m_engine
}
so far so good until i try to derive that out like so
sSpartan : public ship
{
eng_mk1 m_engine;
]
eng_mk1 is a class derivation of Engine, it always initilized the Engine m_engine part in the base class constructor, and eng_mk1 object is never created
I'm pretty sure im going to have to rely on virtual functions... I get the idea, but no the syntax. halp plz?