polymorphism..

Hello,
I am trying to create polymorphic classes but with no luck.
I have .h files and .cpp files.

I am declaring my classes in .h files and defining each function in .cpp files. I have a class called Sprite and a class called Animation that inherits from Sprite.

An Animation object is created inside an Entity object.
Entity.h:

1
2
3
4
5
6
7
8
9
 class Entity
{
private:
	//pointers

	//objects
	Sprite* look;
..
...


Then of course I specify what type of sprite it is in Entity.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void Entity::initialise( Graphics* pGraphics,  //Graphics address
	                     const char* pFile,    //File name address
						 int frameWidth,       //frame with
						 int frameHeight,      //frame height
						 int columns,          //columns
						 int frames,           //frames
						 int startFrame,       //startFrame
						 int currentFrame,     //currentFrame
						 int endFrame )        //endFrame
{
	look = new Animation();
	look->initialise( pGraphics,
		              pFile,
					  frameWidth,
					  frameHeight,
					  columns,
					  frames,
					  startFrame,
					  currentFrame,
					  endFrame );
}


Unfortunately that doesn't compile because it says that my initialise function contains too many arguments. Because Sprite::initialise takes only two arguments, I think the compiler is expecting that one initialise function even though my sprite::initialise function is declared as virtual in sprite.h

What is going wrong?
Should I also define the functions as virtual?
If so, where exactly do we put "virtual" in the definition?

Should I declare Animation::initialise as virtual as well?

Thanks a lot for the help,
Clodi
We have no way to know whether lines 12 to 20 are allowed, we need to see definition of Animation class.

Also, avoid "initialize" and "free" functions - prefer to use constructors and destructors:
http://www.cplusplus.com/doc/tutorial/classes2/
Last edited on
Topic archived. No new replies allowed.