Page 2 of 2
Re: C++ SDL TileMap System ERRORS! HELP! :P
Posted: Sun May 01, 2011 4:41 pm
by JesseGuarascia
VoidElite wrote: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'm pretty sure you're wrong there my friend. Because by the looks of your 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
The problem is your function names. Because this:
Code: Select all
void Tile::TileFile(int id){
sprite->file=("Tiles\\"+id+".bmp").str();
}
and this:
Are not the same function. All of your errors (for the most part), are with the fact that you didn't make it a lowercase "T" on TileFile. That line should really be:
Code: Select all
void Tile::tileFile(int id){
sprite->file = ("Tiles\\"+id+".bmp").str();
}
Also, if you're having problems with the string of characters, why not just use a std::string from the STL library?
Re: C++ SDL TileMap System ERRORS! HELP! :P
Posted: Sun May 01, 2011 5:48 pm
by VoidElite
JesseGuarascia wrote:VoidElite wrote: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'm pretty sure you're wrong there my friend. Because by the looks of your 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
The problem is your function names. Because this:
Code: Select all
void Tile::TileFile(int id){
sprite->file=("Tiles\\"+id+".bmp").str();
}
and this:
Are not the same function. All of your errors (for the most part), are with the fact that you didn't make it a lowercase "T" on TileFile. That line should really be:
Code: Select all
void Tile::tileFile(int id){
sprite->file = ("Tiles\\"+id+".bmp").str();
}
Also, if you're having problems with the string of characters, why not just use a std::string from the STL library?
Ok I've got rid of all errors and it compiles again but when run it flashes up the window then goes away. Thanks to my debug log(log.txt) I have been able to work out that the problem somewhere in Tile.cpp and I think it's because SDL cannot find the file meaning that it brings us back to tileFile:
Code: Select all
void Tile::tileFile(int id){
std::stringstream idTmp;
idTmp<<id;
sprite->file="Tiles\\"+idTmp.str()+".bmp"; //error
}
Ideas?
Re: C++ SDL TileMap System ERRORS! HELP! :P
Posted: Mon May 02, 2011 6:56 am
by MrDeathNote
I would suggest writing out that string to your debug file to see what its actually trying to load. Also try to load the file explicitly. And use the debugger.
Re: C++ SDL TileMap System ERRORS! HELP! :P
Posted: Mon May 02, 2011 7:17 am
by VoidElite
MrDeathNote wrote:I would suggest writing out that string to your debug file to see what its actually trying to load. Also try to load the file explicitly. And use the debugger.
I've tried "debug->debug(tile->sprite->file);" but it compiles but I see no text outputted from this line in fact any form of interaction with the tile and it immediately kicks off. This is quite obvious due to the fact that tile hasn't been initialized but even when I try to initialize it it doesn't work.
It appears to me that there is some form of internal error in either Tile.cpp or Tile.hpp. Again here is their code:
Tile.hpp:
Code: Select all
#ifndef TILE_HPP
#define TILE_HPP
#include <iostream>
#include <sstream>
#include <fstream>
#include <cmath>
#include "SDL\SDL.h"
#include "Windows.h"
#include "Globals.hpp"
#include "Debug.cpp"
#include "Sprite.cpp"
using namespace std;
class Tile{
public:
Tile();
Tile(int id2,int x,int y);
~Tile();
//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){
std::stringstream idTmp;
idTmp<<id;
sprite->file="Tiles\\"+idTmp.str()+".bmp"; //error
}
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;
}
Tile::~Tile(){
delete sprite;
delete this;
}
#endif