Sign in to follow this  
Mizipzor

Errorcheck in GetTileData

Recommended Posts

I have a struct which defines a tile, evert tile got an id number so I can store them in the map file and in the mapvector as ints. Then I need a function that returns the tile represented by a certain tile id. I wrote this:
Tile* GetTileData(int TileID) {
	if( TileData.find(TileID) == TileData.end() ) {	// if the TileID doesnt exist...
		return &TileData[0];	// return the black one
	} 

	return &TileData[TileID];	// otherwise return the specified tile
}
But I get errors:
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(39) : error C2065: 'TileData' : undeclared identifier
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(39) : error C2228: left of '.find' must have class/struct/union type
        type is ''unknown-type''
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(39) : error C2228: left of '.end' must have class/struct/union type
        type is ''unknown-type''
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(39) : error C3861: 'TileData': identifier not found, even with argument-dependent lookup
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(40) : error C3861: 'TileData': identifier not found, even with argument-dependent lookup
d:\Documents\CPP\Visual Studio Projects\TileSystem\AsciiMap.cpp(43) : error C3861: 'TileData': identifier not found, even with argument-dependent lookup

The tiledata is a std::map, std::map <int, Tile> TileData; // holds the information for all the tiles, the data is accessed by the tile ID number I thought ( TileData.find(TileID) == TileData.end() ) was the way to test if an element didnt exist in a std::map. Whats the right way?

Share this post


Link to post
Share on other sites
It looks like that's not your problem, the problem is that your function can't see the TileData declaration. Possible reasons for this include that you forget to include a header, are writing a class member function and didn't put the ClassName:: in front of the function name, or accidently declared something static when it wasn't meant to be. Without seeing more code, it's hard to say what the exact problem is.

Share this post


Link to post
Share on other sites

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