Folks,
I'm having a strange problem where I can't seem to get my program recognise my overloaded constructors. I've declared 2 constructors, one with 6 parameters and then another with 8 parameters as below:-
Code:
SPRITE(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x = 1, float y = 1, int i_lives = 1); //constructor
SPRITE(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x = 1, float y = 1, int i_lives = 1, bool frozen = true, double frozen_end_time = 0);
SPRITE::SPRITE(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x, float y, int i_lives)
{
draw_area = draw_engine_ptr;
pos.x = x;
pos.y = y;
sprite_index = s_index;
num_lives = i_lives;
facing_dir.x=1;
facing_dir.y=0;
classID = SPRITE_CLASSID;
level_ptr = l_ptr;
frozen = false;
frozen_end_time = 0;
}
SPRITE::SPRITE(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x, float y, int i_lives, bool new_frozen, double new_frozen_end_time)
{
draw_area = draw_engine_ptr;
pos.x = x;
pos.y = y;
sprite_index = s_index;
num_lives = i_lives;
facing_dir.x=1;
facing_dir.y=0;
classID = SPRITE_CLASSID;
level_ptr = l_ptr;
frozen = new_frozen;
frozen_end_time = new_frozen_end_time;
}
Now I've got several classes that inherit from this SPRITE class and the majority of them only need to pass into the SPRITE constructor with 6 parameters like below:-
Code:
class CHARACTER : public SPRITE
{
public:
CHARACTER(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x = 1, float y = 1, int lives = 3,
char up_key = 'w', char down_key = 's', char left_key = 'a', char right_key = 'd');
protected:
char up_key;
char down_key;
char left_key;
char right_key;
};
CHARACTER::CHARACTER(LEVEL *l_ptr, DRAW_ENGINE *draw_engine_ptr, int s_index, float x, float y, int lives,
char up, char down, char left, char right)
: SPRITE(l_ptr, draw_engine_ptr, s_index, x, y,lives)
{
up_key = up;
down_key = down;
left_key = left;
right_key = right;
classID = CHARACTER_CLASSID;
}
};
Now I'm explictly calling the SPRITE constructor that has 6 parameters but I keep getting the error:-
error C2668: 'SPRITE::SPRITE' : ambiguous call to overloaded function
Isn't it possible to overload constructors with different parameters ? I've re-checked to ensure that I'm passing in the correct parameters type's etc and all looks good.
Any ideas ?
Cheers
Starkhorn