trouble with pointers

i'm working on a txt based game i have a seperate header
and im getting this error... .here's the code ill post the error at the bottom

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
// World System

#include <iostream>
#include <vector>
#include <string>

using namespace std;

class World
{

public:
	

};

// Enemies

class Enemy : public World
{
		
};

class Mercenary : public World

{
		
};

that is my "header"

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

#include <string>
#include <iostream>
#include <vector>
#include "WorldX.h"

vector<World*> WorldList;

int GetObject(int index)
{
	cout << WorldList[index] << endl;

	return WorldList[index];
}

void GetWorldSize()
{

}

void SpawnObj()
{
	for(int i = 1; i<= 100; i++)
	{
	
		Enemy* enemy = new Enemy();
		Mercenary* merc = new Mercenary();
		
		WorldList.push_back(enemy);
		WorldList.push_back(merc);
	}

	
}
	
// Main Function
void main()
{
	
	GetObject(1);
	SpawnObj();
	cout << WorldList.size() << endl;
}

and this is the error im getting

Error 1 error C2440: 'return' : cannot convert from 'World *' to 'int' c:\users\www\documents\visual studio 2008\projects\enemies\enemies\enemies.cpp 18 Enemies
Use int main().

Line 18 is a blank line in both files so...I'm not sure what the issue is. Try double clicking the error and telling me what line on the code you posted it is.
because i had it trying to get object b4 they spawn.... line 40 and line 41
i just noticed it
and i also had to change int GetObject() to void GetObject and remove returnl;
how can it get an object(address) if they havent spawned it's common sense sorry im just a little slow today
thanks
Last edited on
Ooooh, yeah I see. It's because WorldList[index] is a World*, and you are trying to return an int. They aren't compatible. If you want to return a World*, go ahead and put a World* as the return type.
1
2
3
4
World* GetObject(int index)
{
	return WorldList[index];
}


thats what i had to change it to, inorder to make it work
Topic archived. No new replies allowed.