Yes, you'll use ": public Snake" in your AISnake declaration.
Then, the next step is removing all the identical members from the derived class, since they will already exist in the base class.
Then you write a completely separate constructor, because those are not inherited from the base class. This is true even if its parameters will be identical. More on that below...
Finally, since your update() method is different from that of the base class, you'll need to declare the base class method as "virtual". Otherwise, the polymorphism may not work as you expect when iterating through a loop of generic "Snake" object pointers, for example.
So first, your slightly-updated base class will be:
Code:
class Snake {
//Attributes
protected:
char direction_;
char nd_;
std::list<Position> segments;
UINT nodesize_;
Image nodeimage;
//Snake playerSnake_;
//Operations
public:
Snake(int x, int y);
//updates the position of the snake
virtual void update();
//renders the snake to the canvas
void draw(Canvas& canvas);
//sets the direction the snake will move
void set_direction(char direction);
//gets the direction the snake will move
int get_direction();
};
... and then your derived class definition will look like this:
Code:
class AISnake : public Snake {
//Additional attributes
//(None currently)
//Operations
public:
AISnake(int x, int y);
//updates the position of the snake
virtual void update();
};
Your constructor for AISnake will look like this:
Code:
AISnake::AISnake(int x, int y) :
Snake(x,y)
{
}
You'll see how, even though you have to write a new constructor, you can still simply pass the original parameters to the base class constructor using the initialization list. This assumes you're doing the same thing with x and y in both constructors. If not, obviously you'll write different code based on any different AISnake behavior.
The reason I also declared the AISnake::update() method virtual is twofold: it reminds you that it is an overridden method, but more importantly, if you want to further derive another class from AISnake in the future, AISnake()::update() will need to be virtual as well. You don't have to leave that in if you don't want to, but it's a commonly-used convention.