Why do I get a compile error about redefinitions of instance_create()? There all useing diffrent return types. If I can't do this how can I do it such that it can return the right type?(because if I just return "object" I can't access class percific varibles and functions...)
class object
{
...
};
class obj_ball : public object
{
...
};
class obj_wall : public object
{
...
};
class proj_bullet : public object
{
...
};
obj_ball instance_create()
{
//create the object
obj_ball newobj= new obj_ball;
//cast to "object" class and add to object list
object_list.push_back((object*)newobj);
return newobj;
}
obj_wall instance_create()
{
//create the object
obj_wall newobj= new obj_wall;
//cast to "object" class and add to object list
object_list.push_back((object*)newobj);
return newobj;
}
proj_bullet instance_create()
{
//create the object
proj_bullet newobj= new proj_bullet;
//cast to "object" class and add to object list
object_list.push_back((object*)newobj);
return newobj;
}
int main()
{
obj_ball mynewball = instance_create();
mynewball->move_randomdir();
mynewball->move_randomspeed();
obj_wall wall = instance_create();
}