I am getting a few errors with my code, I know that I am calling for files multiple times after searching around I am just un-sure how I would fix my code.
"Error C2011: 'Actor' : 'class' type redefinition.
//THIS IS MY source.cpp
#include "libtcod.hpp"
#include "Actor.h"
#include "Map.h"
#include "Engine.h"
Engine engine;
int main()
{
int playerx = 40, playery = 25;
TCODConsole::initRoot(80, 50, "libtcod C++ tutorial", false);
while (!TCODConsole::isWindowClosed())
{
TCOD_key_t key;
TCODSystem::checkForEvent(TCOD_EVENT_KEY_PRESS, &key, NULL);
switch (key.vk)
{
case TCODK_UP: playery--;
break;
case TCODK_DOWN: playery++;
break;
case TCODK_LEFT: playerx--;
break;
case TCODK_RIGHT: playerx++;
break;
default:break;
}
TCODConsole::root->clear();
TCODConsole::root->putChar(playerx, playery, '@');
TCODConsole::flush();
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11
//THIS IS MY Actor.h
class Actor
{
public:
int x, y; // position on map
int ch; // ascii code
TCODColor col; // color
Actor(int x, int y, int ch, const TCODColor &col);
void render() const;
};
1 2 3 4 5 6 7 8 9 10 11 12
//THIS IS MY Actor.cpp
#include "libtcod.hpp"
#include "Actor.h"
Actor::Actor(int x, int y, int ch, const TCODColor &col) : x(x), y(y), ch(ch), col(col)
{}
void Actor::render() const
{
TCODConsole::root->setChar(x, y, ch);
TCODConsole::root->setCharForeground(x, y, col);
}
Theres a few others but all are the same error I am hoping I can use the solution to fix the others.
#ifndef // this is where you put the name, typically in caps. I prefer to add _LOCK (aka ACTOR_LOCK)
#define // same name
// class code goes here
#endif
What this little bit of syntax does is it helps your files recognize that they already have "Actor.h" defined within them maybe via another file that was using it, or another file that had it included that they included, and won't try to include it again.
It would be easier to find the error if you have also posted a few lines of build log above the error you are mentioning.
Anyway, it seems that you have actor.h included (directly or indirectly) in one of the other files that you are including ("libtcod.hpp", "Map.h", "Engine.h")
//MAP.h
struct Tile
{
bool canWalk; // Can we walk through this tile?
Tile() : canWalk(true) {}
};
#ifndef MAP_LOCK
#define MAP_LOCK
class Map
{
public :
int width, height;
Map(int width, int height);
~Map();
bool isWall(int x, int y) const;
void render() const;
protected :
Tile *tiles;
void setWall(int x, int y);
};
#endif
With this line im getting pretty much the same error but instead its for a struct --'Tile :'struct' type redefinition.
The "Tile" is called in my Map.cpp