function overloading problem...

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...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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();
}
You're doing it wrong.

1
2
3
4
5
void proj_bullet::proj_bullet() {
// do shit
}

proj_bullet mynewbullet;


Or, you can pass arguments:

1
2
3
4
5
void proj_bullet::proj_bullet(int a, int b) {
x = a; y = b;
}

proj_bullet mynewbullet(3, 4); // at least I think that's right 
Topic archived. No new replies allowed.