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

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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. :)
Last edited by VoidElite on Sun May 01, 2011 4:15 pm, edited 5 times in total.
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

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

Post 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?
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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.
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

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

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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.
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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);
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

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

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

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

Post by dandymcgee »

Did you fix the case sensitivity as well? tileFile() != TileFile()
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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). :)
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

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

Post 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?
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

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

Post by MrDeathNote »

You may want to update the code you posted so we have something to work on.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

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

Post 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?
User avatar
VoidElite
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 54
Joined: Sun Apr 24, 2011 5:25 am
Current Project: Lunar Sanity, 2D engine for PC.
Favorite Gaming Platforms: Playstation
Programming Language of Choice: C
Location: England

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

Post 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();
I love 16-bit Assembly language programming. I'm currently having an affair with C++. I'm working on a 2D Game Engine called Lunar Sanity for PC and soon DC. I own three games consoles: Dreamcast, Xbox 360 and Atari Flashback. I'm on a Mac and soon a PC. I love Windows XP as it works great(can run 16-bit GUIs). I've been programming for 3 years(since I was 11).

I settling into my hybrid(procedural&object orientated) life. It's all good so far. :)
Post Reply