Page 1 of 2

C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 2:44 am
by VoidElite
UPDATED!

Basically I'm working on a 2D Game Engine using SDL as the backend and C++ as the frontend.
But I'm getting some irritating errors with my TileMap system.

Tile.hpp:

Code: Select all

#ifndef TILE_HPP
#define TILE_HPP
#include <iostream>
#include "SDL\SDL.h"
#include "Windows.h"
#include "Globals.hpp"
#include "Sprite.cpp"

using namespace std;

class Tile{
	public:
		Tile();
		Tile(int id2,int x,int y);
		//destructor needed
		void tileFile(int id);
		Sprite *sprite;
		int id;
};
#endif
Tile.cpp:

Code: Select all

#ifndef TILE_CPP
#define TILE_CPP
#include "Tile.hpp"

void Tile::TileFile(int id){
	sprite->file=("Tiles\\"+id+".bmp").str();
}
Tile::Tile(){
	id=0;
	TileFile(id);
	sprite->offset.x=0;
	sprite->offset.y=0;
	sprite->visible=true;
}
Tile::Tile(int id2,int x,int y){
	id=id2;
	TileFile(id);
	sprite->offset.x=x;
	sprite->offset.y=y;
	sprite->visible=true;
}
#endif
Map.hpp:

Code: Select all

#ifndef MAP_HPP
#define MAP_HPP
#include <iostream>
#include "SDL\SDL.h"
#include "Windows.h"
#include "Globals.hpp"
#include "Tile.hpp"

using namespace std;

class Map{
	public:
		Map(int tileIds2[TILE_TOTAL]);
		~Map();
		Tile *tiles[TILE_TOTAL]; 
		void drawAll(SDL_Surface *screen);
};
#endif
Map.cpp:

Code: Select all

#ifndef MAP_CPP
#define MAP_CPP
#include "Map.hpp"

Map::Map(int tileIds2[TILE_TOTAL]){
	int x=0;
	int y=0;
	for(int i=0;i<TILE_TOTAL;i++){
		if(x==649){
			x=0;
			y+=TILE_HPPEIGHT;
			tiles[i]->id=tileIds2[i];
			tiles[i]->sprite->offset.x=x;
			tiles[i]->sprite->offset.y=y;
			tiles[i]->tileFile(tiles[i]->id);
			x++;
		}else{
			x+=TILE_WIDTH;
			tiles[i]->id=tileIds2[i];
			tiles[i]->sprite->offset.x=x;
			tiles[i]->sprite->offset.y=y;
			tiles[i]->tileFile(tiles[i]->id);
			x++;
		}
	}
}
Map::~Map(){
	delete[] tiles;
	delete this;
}
void Map::drawAll(SDL_Surface *screen){
	for(int i=0;i<TILE_TOTAL;i++){
		tiles[i]->sprite->draw(screen);
	}
}
#endif

Errors:

Code: Select all

In file included from src\Main.hpp:11,
                 from src\Main.cpp:1:
src\Tile.cpp:5: error: no `void Tile::TileFile(int)' member function declared in
 class `Tile'
src\Tile.cpp: In member function `void Tile::TileFile(int)':
src\Tile.cpp:6: error: invalid operands of types `const char*' and `const char[5
]' to binary `operator+'
src\Tile.cpp: In constructor `Tile::Tile()':
src\Tile.cpp:10: error: `TileFile' was not declared in this scope
src\Tile.cpp: In constructor `Tile::Tile(int, int, int)':
src\Tile.cpp:17: error: `TileFile' was not declared in this scope
It's really late here and I'm too tired to try and work this out.
All help greatly appreciated as usual. :)

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 4:41 am
by MrDeathNote
In Map.h:

Code: Select all

Tile tiles[TILE_TOTAL]; 
trys to call a no-arg constructor for tiles, since you don't have a no-arg constructor for tiles you'll get an error. You need an array of tile pointers not actual tile objects since you're calling new on them in the Map constructor. This can't be the entire code for this, where are TILE_TOTAL, TILE_WIDTH and TILE_HEIGHT declared?

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 5:07 am
by VoidElite
MrDeathNote wrote:In Map.h:

Code: Select all

Tile tiles[TILE_TOTAL]; 
trys to call a no-arg constructor for tiles, since you don't have a no-arg constructor for tiles you'll get an error. You need an array of tile pointers not actual tile objects since you're calling new on them in the Map constructor. This can't be the entire code for this, where are TILE_TOTAL, TILE_WIDTH and TILE_HEIGHT declared?
There declared in Globals.h, nothing much to see there but a bunch of preprocessor directives and constants(that being one of them).

Going to post the updated code and errors.

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 5:33 am
by MrDeathNote
You still need to make tiles an array of pointers. AND NEVER DELETE THIS, it's a very bad idea. I have a few other problems with this code. You don't need to put ifdef guards around your cpp files. You should never include a .cpp file. You Map destructor should call delete[] on tiles since its an array. Also why are you mixing .h and .hpp file extensions, they're essentially the same. You should pick one and stick with it.

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 5:52 am
by VoidElite
MrDeathNote wrote:You still need to make tiles an array of pointers. AND NEVER DELETE THIS, it's a very bad idea. I have a few other problems with this code. You don't need to put ifdef guards around your cpp files. You should never include a .cpp file. You Map destructor should call delete[] on tiles since its an array. Also why are you mixing .h and .hpp file extensions, they're essentially the same. You should pick one and stick with it.
My bad, change em all to .cpp.

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 6:18 am
by VoidElite
VoidElite wrote:
MrDeathNote wrote:You still need to make tiles an array of pointers. AND NEVER DELETE THIS, it's a very bad idea. I have a few other problems with this code. You don't need to put ifdef guards around your cpp files. You should never include a .cpp file. You Map destructor should call delete[] on tiles since its an array. Also why are you mixing .h and .hpp file extensions, they're essentially the same. You should pick one and stick with it.
My bad, change em all to .cpp.
Ok I've made it an array of pointers ext. now I'm getting these errors:

Code: Select all

C:\Users\MARCAR~1\AppData\Local\Temp/cceCbaaa.o:Main.cpp:(.text+0x3ef6): undefin
ed reference to `Tile::tileFile()'
C:\Users\MARCAR~1\AppData\Local\Temp/cceCbaaa.o:Main.cpp:(.text+0x3f54): undefin
ed reference to `Tile::tileFile()'
C:\Users\MARCAR~1\AppData\Local\Temp/cceCbaaa.o:Main.cpp:(.text+0x3ff2): undefin
ed reference to `Tile::tileFile()'
C:\Users\MARCAR~1\AppData\Local\Temp/cceCbaaa.o:Main.cpp:(.text+0x4050): undefin
ed reference to `Tile::tileFile()'
collect2: ld returned 1 exit status
This is the code it's talking about in Main.cpp:

Code: Select all

int homeIds[50]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
home=new Map(homeIds);

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 6:36 am
by MrDeathNote
Ehh tileFile() is never defined:

Code: Select all

void tileFile();

Code: Select all

void Tile::TileFile(int id){
   sprite->file="Tiles\\"+id+".bmp";
}
These are not even remotely the same function.

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 6:45 am
by VoidElite
MrDeathNote wrote:Ehh tileFile() is never defined:

Code: Select all

void tileFile();

Code: Select all

void Tile::TileFile(int id){
   sprite->file="Tiles\\"+id+".bmp";
}
These are not even remotely the same function.
Ah, my bad again. I've matched up the operands. But somehow I'm still getting this:

Code: Select all

C:\Users\MARCAR~1\AppData\Local\Temp/cc4Gcaaa.o:Main.cpp:(.text+0x3f06): undefin
ed reference to `Tile::tileFile(int)'
C:\Users\MARCAR~1\AppData\Local\Temp/cc4Gcaaa.o:Main.cpp:(.text+0x3f74): undefin
ed reference to `Tile::tileFile(int)'
C:\Users\MARCAR~1\AppData\Local\Temp/cc4Gcaaa.o:Main.cpp:(.text+0x4022): undefin
ed reference to `Tile::tileFile(int)'
C:\Users\MARCAR~1\AppData\Local\Temp/cc4Gcaaa.o:Main.cpp:(.text+0x4090): undefin
ed reference to `Tile::tileFile(int)'
collect2: ld returned 1 exit status

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 12:16 pm
by dandymcgee
Did you fix the case sensitivity as well? tileFile() != TileFile()

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 12:30 pm
by VoidElite
dandymcgee wrote:Did you fix the case sensitivity as well? tileFile() != TileFile()
Of course I'd only use 'TileFile' if it was a class name. It's an function so I've never had that problem. I seriously can't see what's the problem. From what I can see I have no arbitrary definitions of the tileFile function.

Please help guys need to get this finished so I can move onto my Level Editor(.net). :)

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 2:22 pm
by N64vSNES

Code: Select all

C:\Users\MARCAR~1\AppData\Local\Temp/ccGIbaaa.o:Main.cpp:(.text+0x3f06): undefin
ed reference to `Tile::tileFile(int)'
Did you include the header in Main.cpp?

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 3:19 pm
by VoidElite
N64vSNES wrote:

Code: Select all

C:\Users\MARCAR~1\AppData\Local\Temp/ccGIbaaa.o:Main.cpp:(.text+0x3f06): undefin
ed reference to `Tile::tileFile(int)'
Did you include the header in Main.cpp?
Yes.
Here's the new errors:

Code: Select all

In file included from src\Main.hpp:11,
                 from src\Main.cpp:1:
src\Tile.cpp:5: error: no `void Tile::TileFile(int)' member function declared in
 class `Tile'
src\Tile.cpp: In member function `void Tile::TileFile(int)':
src\Tile.cpp:6: error: invalid operands of types `const char*' and `const char[5
]' to binary `operator+'
src\Tile.cpp: In constructor `Tile::Tile()':
src\Tile.cpp:10: error: `TileFile' was not declared in this scope
src\Tile.cpp: In constructor `Tile::Tile(int, int, int)':
src\Tile.cpp:17: error: `TileFile' was not declared in this scope

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 3:59 pm
by MrDeathNote
You may want to update the code you posted so we have something to work on.

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 4:15 pm
by N64vSNES
MrDeathNote wrote:You may want to update the code you posted so we have something to work on.
Exactly this^

Can you include Main.cpp too?

Re: C++ SDL TileMap System ERRORS! HELP! :P

Posted: Sun May 01, 2011 4:17 pm
by VoidElite
N64vSNES wrote:
MrDeathNote wrote:You may want to update the code you posted so we have something to work on.
Exactly this^

Can you include Main.cpp too?
Main.cpp is the file being compiled it is irrelevant to these errors. I've updated it.

This statement in the tileFile function is the problem:

Code: Select all

sprite->file=("Tiles\\"+id+".bmp").str();