Sign in to follow this  

C++ Classes Help (Long Code Quote)

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My code is shown below, as are the errors I am receiving. I cannot see what I am doing incorrectly here, however, whatever it is, I am most-likely doing it across all of my classes, thus causing the massive amount of errors seen. Class Location:
#pragma once

class Location
{
public:
	Location::Location(int xco, int yco);
	Location::Location(float xco, float yco);
	Location::~Location(void);
	int Location::GetX();
	float Location::GetX();
	int Location::GetY();
	float Location::GetY();
	void Location::SetX(int xco);
	void Location::SeyX(float xco);
	void Location::SetY(int yco);
	void Location::SetY(float yco);
private:
	float x;
	float y;
};

Location::Location(int xco, int yco)
// Constructor using ints as positions
{
	SetX(xco);
	SetY(yco);
}

Location::Location(float xco, float yco)
// Constructor using floats as positions
{
	SetX(int(xco));
	SetY(int(yco));
}

Location::~Location(void)
{
}

int Location::GetX()
{
	return (int(x));
}
float Location::GetX()
{
	return x;
}
int Location::GetY()
{
	return (int(y));
}
float Location::GetY()
{
	return y;
}
void Location::SetX(int xco)
{
	x = xco;
}
void Location::SetX(float xco)
{
	x = xco;
}
void Location::SetY(float yco)
{
	y = yco;
}
void Location::SetY(float yco)
{
	y = yco;
}

Class Tile:
#pragma once

enum TileStatus
{
	Sky;
	BuildableIsland;
	UnbuildableIsland;
	UsedIsland;
	Bridge;
};

enum TileSurroundings
{
	EmptySurroundsAll;

};

class Tile
{
public:
	Tile::Tile(Location TLoc);
	Tile::Tile(int x, int y);
	Tile::~Tile(void);
	Location Tile::GetTileLocation();
	void Tile::SetTileLocation(Location TLoc);
	void Tile::SetTileLocation(int x, int y);
private:
	TileStatus TheTileStatus;
	Location TheTileLocation;
};


Tile(Location &TLoc)
{
	TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
	TheTileLocation = TLoc; // sets the tile's location (x,y coordinates) to a predefined location on the map
}

Tile::Tile(int x, int y)
{
	TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
	TheTileLocation = new Location(x,y); // sets the tile's location (x,y coordinates) to a predefined location on the map
}

Tile::~Tile(void)
{
}

Location Tile::GetTileLocation()
{
	return TheTileLocation;
}
void Tile::SetTileLocation(Location &TLoc)
{
	TheTileLocation = TLoc;
}
void Tile::SetTileLocation(int x, int y)
{
	TheTileLocation = new Location(x, y);
}

Class Worldmap (my toplevel class that contains tiles and locations):
#include "Location.cpp"
#include "Tile.cpp"

#pragma once

class WorldMap
{
public:
	WorldMap(void);
	~WorldMap(void);
private:
	ClearMap(Tile &TilesArray);
};

WorldMap::WorldMap(void)
{
	// Called ONCE per game:
	Tile TilesArray = Tile[256*32][256*32]; // There are (256 * 32) horizontal tiles per map, and (256 * 32) vertical tiles per map - thus making a map of 67,108,864 tiles.
	ClearMap(&TilesArray);
}

WorldMap::~WorldMap(void)
{
	ClearMap(&TilesArray);
}
void WorldMap::ClearMap(Tile &TilesArray)
{
	for (int x = 0; x < (256 * 32); x++)
	{
		for (int y = 0; y < (256 * 32); y++)
		{
			TilesArray[x][y] = Tile(x, y);
		}
	}
}

The errors generated (multiples of the same errors, I realize):
Quote:
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2059: syntax error : ')' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2059: syntax error : ')' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2059: syntax error : ')' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(12): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(29): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(7): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(11): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(12): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(29): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(12): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(29): error C2061: syntax error : identifier 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(9): error C2061: syntax error : identifier 'Tile' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(9): error C2061: syntax error : identifier 'Tile' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(12): error C2065: 'TheTileLocation' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(14): error C2065: 'TilesArray' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(14): error C2065: 'TilesArray' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2065: 'TLoc' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2065: 'TLoc' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2065: 'TLoc' : undeclared identifier c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2084: function 'int Location::GetX(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2084: function 'int Location::GetX(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2084: function 'int Location::GetX(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2084: function 'int Location::GetY(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2084: function 'int Location::GetY(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2084: function 'int Location::GetY(void)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(50): error C2084: function 'void Location::SetY(float)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(50): error C2084: function 'void Location::SetY(float)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(50): error C2084: function 'void Location::SetY(float)' already has a body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ')' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ')' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ')' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ';' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ';' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2143: syntax error : missing ';' before '&' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2143: syntax error : missing ';' before 'Tile::GetTileLocation' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2143: syntax error : missing ';' before 'Tile::GetTileLocation' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2143: syntax error : missing ';' before 'Tile::GetTileLocation' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(10): error C2146: syntax error : missing ';' before identifier 'GetTileLocation' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2146: syntax error : missing ';' before identifier 'TheTileLocation' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(8): error C2275: 'Tile' : illegal use of this type as an expression c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(8): error C2275: 'Tile' : illegal use of this type as an expression c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2371: 'Location' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2371: 'Location' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2371: 'Location' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2371: 'Location::GetX' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(9) : see declaration of 'Location::GetX' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2371: 'Location::GetY' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(20): error C2371: 'Tile::GetTileLocation' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(20): error C2371: 'Tile::GetTileLocation' : redefinition; different basic types c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(24): error C2448: 'Tile::SetTileLocation' : function-style initializer appears to be a function definition c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(24): error C2448: 'Tile::SetTileLocation' : function-style initializer appears to be a function definition c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(24): error C2448: 'Tile::SetTileLocation' : function-style initializer appears to be a function definition c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(4): error C2470: 'TLoc' : looks like a function definition, but there is no formal parameter list; skipping apparent body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(4): error C2470: 'TLoc' : looks like a function definition, but there is no formal parameter list; skipping apparent body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(4): error C2470: 'TLoc' : looks like a function definition, but there is no formal parameter list; skipping apparent body c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2501: 'Location' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2501: 'Location' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(19): error C2501: 'Location' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(10): error C2501: 'Tile::Location' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2501: 'Tile::Location' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2501: 'Tile::TheTileLocation' : missing storage-class or type specifiers c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(42): error C2511: 'void Location::SetX(float)' : overloaded member function not found in 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(42): error C2511: 'void Location::SetX(float)' : overloaded member function not found in 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(42): error C2511: 'void Location::SetX(float)' : overloaded member function not found in 'Location' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(17): error C2511: 'void WorldMap::ClearMap(Tile &)' : overloaded member function not found in 'WorldMap' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(17): error C2511: 'void WorldMap::ClearMap(Tile &)' : overloaded member function not found in 'WorldMap' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(10): error C2512: 'Location' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(10): error C2512: 'Location' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2512: 'Tile' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(8): error C2512: 'Tile' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(3): error C2512: 'Tile' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(8): error C2512: 'Tile' : no appropriate default constructor available c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(10): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(26): error C2556: 'float Location::GetX(void)' : overloaded function differs only by return type from 'int Location::GetX(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(12): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(34): error C2556: 'float Location::GetY(void)' : overloaded function differs only by return type from 'int Location::GetY(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(20): error C2556: 'int Tile::GetTileLocation(void)' : overloaded function differs only by return type from 'Location Tile::GetTileLocation(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(20): error C2556: 'int Tile::GetTileLocation(void)' : overloaded function differs only by return type from 'Location Tile::GetTileLocation(void)' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(9): error C2660: 'WorldMap::ClearMap' : function does not take 1 arguments c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(9): error C2660: 'WorldMap::ClearMap' : function does not take 1 arguments c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2676: binary '&' : 'Tile' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2676: binary '&' : 'Tile' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C2676: binary '&' : 'Tile' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(4): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(5): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(6): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(7): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(8): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(14): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(4): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(5): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(6): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(7): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(8): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(14): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(4): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(5): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(6): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(7): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(8): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\TileStatus.h(14): error C2760: syntax error : expected ',' not ';' c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C3861: 'Location': identifier not found, even with argument-dependent lookup c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C3861: 'Location': identifier not found, even with argument-dependent lookup c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(23): error C3861: 'Location': identifier not found, even with argument-dependent lookup c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(21): error C3861: 'TheTileLocation': identifier not found, even with argument-dependent lookup c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(29): error C3861: 'TheTileLocation': identifier not found, even with argument-dependent lookup
Now, can someone see what I am doing wrong, because I can't!

Share this post


Link to post
Share on other sites

enum TileStatus
{
Sky,
BuildableIsland,
UnbuildableIsland,
UsedIsland,
Bridge
};

enum TileSurroundings
{
EmptySurroundsAll

};

...

Tile::Tile(Location &TLoc)
{
TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
TheTileLocation = TLoc; // sets the tile's location (x,y coordinates) to a predefined location on the map
}





They are elements. Use a ',' not a ';'. Also, you forgot the scope on the constructor. Thats all I noticed on a really quick glance.

Also, including cpp files is generally frowned upon. You should have header and code files. Including cpp files is going to lead to multiple declaration errors. You should split up definitions into header files, and declarations into source files.

Share this post


Link to post
Share on other sites
Okay, this will take a few minutes but the first error ive noticed is that you are declaring multiple functions that have the same signature, but return different values.

int Location::GetX();
float Location::GetX();

As both functions have the same name, when you call GetX() the compiler wont know which function to call. Hence, they have to be given different names, or removing one function entirely (you could probably remove the function that returns an int, as you could cast to an int from the returned float if need be)

A lot of those errors look like your missing semi colons, those kinds of errors should be found easy enough

Share this post


Link to post
Share on other sites
Are you not using header files? for instance a class.h and a class.cpp? Or are you writing it all in a .cpp file?

Also something that might help out a bit, at the beginning of each header file or what not add a,

#ifndef __LOCATION_H__
#define __LOCATION_H__


then at the end of the file add a,

#endif

that way they wont be included twice. Then at the top of yer tile class add a,

#include "Location.h"

or .cpp wherever its kept... that will allow yer tile class to use a Location object.

Share this post


Link to post
Share on other sites
I am using a .cpp and a .h file, and including CPPs and from there using a #include "classname.h" at the top of the file. I did not include this section and copy-pasted the code from the .Hs into the source
sections because I felt this post was long enough as it is. Sorry if I destroyed clarification in the process.

[Edited by - DragonGeo2 on April 4, 2006 3:53:10 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by DragonGeo2
I am using a .cpp and a .h file, and including CPPs and from there using a #include "classname.h" at the top of the file. I did not include this section and copy-pasted the code from the .Hs into the *** Source Snippet Removed *** sections because I felt this post was long enough as it is. Sorry if I destroyed clarification in the process.


ok I see... it would be nicer to see the headers and cpps seperate. Note that if its in the header file if you have,

class Location
{
Location::Location( void );
}

you only really need to do a,

class Location
{
Location( void );
}


EDIT:

also note that,

enum TileStatus
{
Sky;
BuildableIsland;
UnbuildableIsland;
UsedIsland;
Bridge;
};

needs to be:

enum TileStatus
{
Sky,
BuildableIsland,
UnbuildableIsland,
UsedIsland,
Bridge
};

Because yer really making them 0, 1, 2, 3, 4,... which is one line of code, not multiple as u used ";"

Share this post


Link to post
Share on other sites
Also note:

Tile::Tile(int x, int y)
{
TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
TheTileLocation = new Location(x,y); // sets the tile's location (x,y coordinates) to a predefined location on the map
}





is fine, but in yer header you need to change the definition of TheTileLocation to :

Location* TheTileLocation;

its really a pointer to the heap when u use 'new'. So then in yer ~Tile() put a:


Tile::~Tile(void)
{
if(TheTileLocation != NULL)delete TheTileLocation;
}






EDIT:

Also note that Tile does not have a default constructor: Tile( void );

so if you go to create an array like you have tile[..][..], you need to pass in a variable either a Tile(int, int), or a Tile(Location).

Share this post


Link to post
Share on other sites
Quote:
Also note that Tile does not have a default constructor: Tile( void );

so if you go to create an array like you have tile[..][..], you need to pass in a variable either a Tile(int, int), or a Tile(Location).

I did this on purpose because I wanted the Tile object to automatically assume its location is 0,0 and that it be actually told its location on the worldmap that way - it seems to make it easier to code, as you can never have a tile that doesn't know its own location (because that would be purposeless).

Share this post


Link to post
Share on other sites
Quote:
Original post by DragonGeo2
Quote:
Also note that Tile does not have a default constructor: Tile( void );

so if you go to create an array like you have tile[..][..], you need to pass in a variable either a Tile(int, int), or a Tile(Location).

I did this on purpose because I wanted the Tile object to automatically assume its location is 0,0 and that it be actually told its location on the worldmap that way - it seems to make it easier to code, as you can never have a tile that doesn't know its own location (because that would be purposeless).


Ok then under yer class Tile, make a,



class Tile
{
...
Tile(void);
...
}


Tile::Tile( void )
{
TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
TheTileLocation = new Location(0,0); // sets the tile's location (0,0 coordinates) to a predefined location on the map
}




you see, you didnt have a default constructor that was being called, you were calling Tile( void ); but it didnt exist... so it wasnt setting anything to 0 like you wanted. IE, it was calling a function that didnt exist.

Share this post


Link to post
Share on other sites
After about ten or so revisions based on the feedback of the community, I was able to reduce the number of errors (and unfortunately increase the number of warnings) by a factor of 0.5. I've added more default constructors with (void) arguments, fixed the problems with using semicolons instead of commas in the enumerations, and even increased the scope in that pesky WorldMap constructor. This is good progress, however, the code still won't compile. I'm going to post the revised files' sources up again, but this time, in a manner that is easier to understand for most.
First, the bad news:
Quote:

c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(12): error C2059: syntax error : ')'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(14): error C2059: syntax error : ')'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(16): error C2061: syntax error : identifier 'Location'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(44): error C2061: syntax error : identifier 'Location'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(16): error C2062: type 'float' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(9): error C2062: type 'int' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(20): error C2062: type 'int' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(4): error C2062: type 'void' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(8): error C2062: type 'void' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(4): error C2062: type 'void' unexpected
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(28): error C2065: 'TheTileLocation' : undeclared identifier
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(21): error C2065: 'TilesArray' : undeclared identifier
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(38): error C2065: 'TLoc' : undeclared identifier
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(14): error C2143: syntax error : missing ')' before '&'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(14): error C2143: syntax error : missing ';' before '&'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(5): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(11): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(18): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(9): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(21): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(5): error C2143: syntax error : missing ';' before '{'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(34): error C2143: syntax error : missing ';' before 'Tile::GetTileLocation'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(12): error C2146: syntax error : missing ')' before identifier 'TLoc'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2146: syntax error : missing ';' before identifier 'GetTileLocation'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(20): error C2146: syntax error : missing ';' before identifier 'TheTileLocation'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(15): error C2146: syntax error : missing ';' before identifier 'TilesArray'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(12): error C2146: syntax error : missing ';' before identifier 'TLoc'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2327: 'Tile::Location' : is not a type name, static, or enumerator
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(16): error C2327: 'Tile::Location' : is not a type name, static, or enumerator
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(20): error C2327: 'Tile::Location' : is not a type name, static, or enumerator
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(16): error C2371: 'WorldMap::ClearMap' : redefinition; different basic types
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(14): error C2373: 'Location' : redefinition; different type modifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(34): error C2373: 'Location' : redefinition; different type modifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(5): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(11): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(18): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(9): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(21): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(5): error C2447: '{' : missing function header (old-style formal list?)
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(39): error C2448: 'Tile::SetTileLocation' : function-style initializer appears to be a function definition
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(12): error C2460: 'Tile::Location' : uses 'Tile', which is being defined
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(15): error C2470: 'TLoc' : looks like a function definition, but there is no formal parameter list; skipping apparent body
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(34): error C2501: 'Location' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): error C2501: 'Tile::Location' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(20): error C2501: 'Tile::Location' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(20): error C2501: 'Tile::TheTileLocation' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(12): error C2501: 'Tile::TLoc' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(15): error C2501: 'WorldMap::Tile' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(15): error C2501: 'WorldMap::TilesArray' : missing storage-class or type specifiers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(40): error C2511: 'void Location::SetX(float)' : overloaded member function not found in 'Location'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(30): error C2541: 'delete' : cannot delete objects that are not pointers
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(16): error C2556: 'void WorldMap::ClearMap(void)' : overloaded function differs only by return type from 'int WorldMap::ClearMap(void)'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(23): error C2588: '::~Location' : illegal global destructor
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(26): error C2588: '::~Tile' : illegal global destructor
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(11): error C2588: '::~WorldMap' : illegal global destructor
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(38): error C2597: illegal reference to non-static member 'Tile::Location'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(21): error C2660: 'Tile' : function does not take 2 arguments
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(13): error C3861: 'ClearMap': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(30): error C3861: 'TheTileLocation': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(36): error C3861: 'TheTileLocation': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(44): error C3861: 'TheTileLocation': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(6): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(4): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(5): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.h(23): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(23): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(18): warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.h(14): warning C4183: 'ClearMap': missing return type; assumed to be a member function returning 'int'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.h(15): warning C4183: 'GetTileLocation': missing return type; assumed to be a member function returning 'int'
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Location.cpp(25): warning C4508: 'Location' : function should return a value; 'void' return type assumed
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\Tile.cpp(32): warning C4508: 'Tile' : function should return a value; 'void' return type assumed
c:\Documents and Settings\DragonGeo2\My Documents\Visual Studio Projects\NSRM\WorldMap.cpp(14): warning C4508: 'WorldMap' : function should return a value; 'void' return type assumed


Now, the individual class' files (with .H files being called first, and listed first):

WorldMap.h:

#ifndef Worldmap_H
#define Worldmap_H

#pragma once

#include "Tile.h";

class WorldMap
{
public:
WorldMap(void);
~WorldMap(void);
private:
ClearMap(void);
Tile TilesArray[256*32][256*32]; // Updated the scope of this to exist outside of the constructor
};

#include "WorldMap.cpp";

#endif




Now, WorldMap.cpp:

#ifndef Worldmap_CPP
#define Worldmap_CPP

WorldMap(void)
{
// Called ONCE per game:
// There are (256 * 32) horizontal tiles per map, and (256 * 32) vertical tiles per map - thus making a map of 67,108,864 tiles.
ClearMap(&TilesArray);
}

~WorldMap(void)
{
ClearMap();
}
void WorldMap::ClearMap(void)
{
for (int x = 0; x < (256 * 32); x++)
{
for (int y = 0; y < (256 * 32); y++)
{
TilesArray[x][y] = Tile(x, y);
}
}
}
#endif




Now for Tile.h:

#ifndef Tile_H
#define Tile_H
#pragma once
#include "TileStatus.h";
#include "Location.h";


class Tile
{
public:
Tile(void);
Tile(Location TLoc);
Tile(int x, int y);
~Tile(void);
Location GetTileLocation();
void SetTileLocation(Location TLoc);
void SetTileLocation(int x, int y);
private:
TileStatus TheTileStatus;
Location TheTileLocation;
};

#include "Tile.cpp";

#endif




And the enumerations file, TileStatus.h:

enum TileStatus
{
Sky,
BuildableIsland,
UnbuildableIsland,
UsedIsland,
Bridge
};

enum TileSurroundings
{
EmptySurroundsAll

};



And Tile.cpp:

#ifndef Tile_CPP
#define Tile_CPP

#ifndef Location_H
#include "Location.h";
#endif

Tile(void)
{
TheTileStatus = Sky;
TheTileLocation = new Location(0,0);
}

Tile(Location &TLoc)
{
TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
TheTileLocation = TLoc; // sets the tile's location (x,y coordinates) to a predefined location on the map
}

Tile(int x, int y)
{
TheTileStatus = Sky; // initializes the status of the tile to be "sky" or blank tile
Location* TheTileLocation = new Location(x,y); // sets the tile's location (x,y coordinates) to a predefined location on the map
}

~Tile(void)
{
if(TheTileLocation != NULL)
{
delete TheTileLocation;
}
}

Location Tile::GetTileLocation()
{
return TheTileLocation;
}
void Tile::SetTileLocation(Location &TLoc)
{
TheTileLocation = TLoc;
}
void Tile::SetTileLocation(int x, int y)
{
TheTileLocation = new Location(x, y);
}
#endif




Finally, Location.h:

#ifndef Location_H
#define Location_H
#pragma once

class Location
{
public:
Location(void);
Location(int xco, int yco);
Location(float xco, float yco);
~Location(void);
float GetX();
float GetY();
void SetX(int xco);
void SeyX(float xco);
void SetY(int yco);
void SetY(float yco);
private:
float x;
float y;
};

#include "Location.cpp";

#endif




And last but not least, Location.cpp:

#ifndef Location_CPP
#define Location_CPP

Location(void)
{
SetX(0);
SetY(0);
}
Location(int xco, int yco)
// Constructor using ints as positions
{
SetX(xco);
SetY(yco);
}

Location(float xco, float yco)
// Constructor using floats as positions
{
SetX(int(xco));
SetY(int(yco));
}

~Location(void)
{
}

float Location::GetX()
{
return x;
}
float Location::GetY()
{
return y;
}
void Location::SetX(int xco)
{
x = (float(xco));
}
void Location::SetX(float xco)
{
x = xco;
}
void Location::SetY(int yco)
{
y = (float(yco));
}
void Location::SetY(float yco)
{
y = yco;
}
#endif




Thanks for all the help people have reccomended previously, let's keep up the good work people!

Share this post


Link to post
Share on other sites
I thought the other posters were pretty clear on this point, but then again I'm not a newbie, so I forgive you :)

DO NOT use a line like #include <something.cpp>

You should read the link: http://www.gamedev.net/reference/programming/features/orgfiles/

You only include header files in cpp files and header files. You never include cpp files.

Basically, you put class/struct definitions, function prototypes, global variables(as extern), typedefs, constants, and #defines

in order, this is the stuff above.
header.h
#ifndef HEADER_H
#define HEADER_H
#include <string> /* we use string, so include it */
/* class definition */
class CClass { /* or struct in place of class, they're identical in C++ */
private:
int private_var;
public:
CClass();
~CClass();
int getPrivate();
};

/* function prototype */
void printSomething(const std::string &something);

/* global variable */
extern int I_AM_EVERY_WHERE;

/* typedefinition */
typedef CClass aClass;

/* constant */
const int bad_boy = 10;

/* define */
#define square(x) x*x

#endif



and the associated cpp file header.cpp

#include <iostream>
#include <string> /* we use iostream, string and header.h, so include them */
#include "header.h"
CClass::CClass { private_var = 0; }
CClass::~CClass { /* unitialize stuff */ }
int CClass::getPrivate() { return private_var; }

int I_AM_EVERY_WHERE;

/* note how I'm prefixing string, cout, and endl with std::, because
* you should avoid using using namespace std; */

void printSomething(const std::string &something) {
std::cout << something << std::endl;
}

And finally, in your main.cpp file you'd do something like this:

#include <iostream>
#include <header.h>

int main()
{
aClass temp;
std::cout << "private: " << temp.getPrivate(); << std::endl;

return 0;
}



There are times when you are including a cpp file in your header file. I'm sure this is causing several problems as the very first error looks like it's coming from tile.h in line 12. there's nothing wrong with this line which means there error comes from earlier. so I looked in last header file you added and looked in location.h

At the bottom of location.h you include location.cpp. So logically I'm going to assume the error is there, but because you shouldn't be including cpp files in header files(or anywhere for that matter) I'm going to tell you to read that link and change your code until you don't include cpp files and then if you're still having problems I'll help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
You mispelled SetX in your location class. You have SetX() and SeyX().

Thanks but I'm still getting a zillion errors.

Share this post


Link to post
Share on other sites
Problem one,
------------------------------------------------------------------------------
Under...

Class Tile
{
...
}

yer,
Location TheTileLocation;
needs to be changed to,
Location* TheTileLocation;

Then in make yer,

Tile::~Tile( void )
{
if(TheTileLocation != NULL) delete TheTileLocation;
}


Next problem:
------------------------------------------------------------------------------
What the last poster said, goto the top of WorldMap.h and replace:

#include "Location.cpp"
#include "Tile.cpp"

with,

#include "Location.h"
#include "Tile.h"


Also, like the last poster said, YOU SHOULD NEVER INCLUDE .CPP.
that being said, at the end of Tile.h take out the include .cpps...they are not needed.


Next problem:
--------------------------------------------------------------------------------
you dont need to if define any CPP files, just the at the top of yer .h files. So you can safely remove those

Next problem:
-----------------------------------------------------------------------------

Under yer location class, you cant have two functions of the same name return 2 different variables...

So, all the GetX() and GetY() functions need to have different names, like so:

Location::GetXAsFloat(), GetYAsInt()...
The Set..() functions are fine because the input is another type... its just the output needs different.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Alright, after much cleaning-up and revising the code as many times as needed to conform to the standards of the posters, I'm still getting some of the errors I've been getting this entire time. Most notably:
Quote:

h:\NSRM\Location.cpp(6): error C2065: 'SetX' : undeclared identifier
h:\NSRM\Location.cpp(7): error C2065: 'SetY' : undeclared identifier
h:\NSRM\Location.cpp(8): warning C4508: 'Location' : function should return a value; 'void' return type assumed
h:\NSRM\Location.cpp(14): warning C4508: 'Location' : function should return a value; 'void' return type assumed
h:\NSRM\Location.cpp(21): warning C4508: 'Location' : function should return a value; 'void' return type assumed
h:\NSRM\Location.cpp(23): error C2588: '::~Location' : illegal global destructor
h:\NSRM\Location.cpp(24): error C2084: function 'int Location(void)' already has a body
h:\NSRM\Location.cpp(27): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(29): error C2065: 'x' : undeclared identifier
h:\NSRM\Location.cpp(31): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(33): error C2065: 'y' : undeclared identifier
h:\NSRM\Location.cpp(35): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(36): error C2365: 'SetX' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(39): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(40): error C2365: 'SetX' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(43): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(44): error C2365: 'SetY' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(47): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(48): error C2365: 'SetY' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Tile.cpp(6): error C2065: 'TheTileStatus' : undeclared identifier
h:\NSRM\Tile.cpp(6): error C2065: 'Sky' : undeclared identifier


When double-clicking on these items in the IDE's error window - it takes me to the line shown. There seems to be confusion within the progrm as to the definition of the Location class, although I made sure to put #include "Location.h" before Tile and WorldMap in the main file.
Does anyone know why this is happening?
-DragonGeo2

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://img360.imageshack.us/img360/4253/undefined4jf.png
I don't see why it thinks "Location" is an "undefined identifier" although the IDE simply finds it quite defined, as per this screenshot...
-DG

Share this post


Link to post
Share on other sites
Don't write this much code at once until you have practice figuring out these things on your own. Take out a bunch of stuff, get the remaining things to *work*, and then put the rest back in gradually.

Share this post


Link to post
Share on other sites
Quote:
Original post by DragonGeo2
Yeah it kinda works when I comment out the line:
#include "WorldMap.h"

Can anyone answer me why my program isn't working?


I would agree with the other poster, you really should pickup a good book on programming basics.... All these errors would be understandable even by reading Visual C++ in 21 Days. Published by Sams publishing(I think still).

here are some of yer errors, lets see if we can understand them:

h:\NSRM\Location.cpp(6): error C2065: 'SetX' : undeclared identifier
h:\NSRM\Location.cpp(7): error C2065: 'SetY' : undeclared identifier

-These 2 mean that SetX() and SetY() dont exist, Probably because u renamed them? double click the error to find where it is calling the wrong name.

h:\NSRM\Location.cpp(8): warning C4508: 'Location' : function should return a value; 'void' return type assumed
h:\NSRM\Location.cpp(14): warning C4508: 'Location' : function should return a value; 'void' return type assumed
h:\NSRM\Location.cpp(21): warning C4508: 'Location' : function should return a value; 'void' return type assumed

-These warnings simply mean you did not return anything from Location. Try returning void...


h:\NSRM\Location.cpp(23): error C2588: '::~Location' : illegal global destructor
h:\NSRM\Location.cpp(24): error C2084: function 'int Location(void)' already has a body
-You have two bodies of code for Location, try finding where the second is and take it out. remove it most likely.

h:\NSRM\Location.cpp(27): error C2653: 'Location' : is not a class or namespace name
-This just means that because of the previous errors, Location could not be compiled and hence doesnt exist


h:\NSRM\Location.cpp(29): error C2065: 'x' : undeclared identifier
h:\NSRM\Location.cpp(31): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(33): error C2065: 'y' : undeclared identifier
h:\NSRM\Location.cpp(35): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(36): error C2365: 'SetX' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(39): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(40): error C2365: 'SetX' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(43): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(44): error C2365: 'SetY' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Location.cpp(47): error C2653: 'Location' : is not a class or namespace name
h:\NSRM\Location.cpp(48): error C2365: 'SetY' : redefinition; previous definition was a 'formerly unknown identifier'
h:\NSRM\Tile.cpp(6): error C2065: 'TheTileStatus' : undeclared identifier
h:\NSRM\Tile.cpp(6): error C2065: 'Sky' : undeclared identifier

-The rest of these should most likely be dealing with the previous errors, and will prolly need little adjusting after the first ones are fixed.

Share this post


Link to post
Share on other sites

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this