I'm trying to create a tile system which creates a single instance of a tile, and adds the tile to an array of tiles, allowing you to call Tile::s_tileList[1]
to get the dirt tile.
However, I'm having some issues with it. Here's the complete tile code:
tile.h
#pragma once
class Tile {
public:
static const Tile s_tileList[128]
static const Tile s_dirt;
Tile(int tileId);
virtual ~Tile();
protected:
private:
int m_tileId;
};
tile.cpp
#include "tile.h"
#include "tile_dirt.h"
const Tile Tile::s_dirt = TileDirt(1); // This line errors
Tile::Tile(int tileId) {
s_tileList[tileId] = *this;
m_tileId = tileId;
}
Tile::~Tile() {
}
tile_dirt.h
#pragma once
#include "tile.h"
class TileDirt : Tile {
public:
TileDirt(int tileId);
virtual ~TileDirt();
protected:
private:
};
When I'm trying to assign s_dirt
to TileDirt
I get the following error:
conversion to inaccessible base class "Tile" is not allowed
What am I doing wrong here?
I tried doing:
static const Tile* s_dirt;
And assign it like:
const Tile* Tile::s_dirt = new TileDirt(1);
But that just adds another error: no suitable constructor exists to convert from "const Tile *" to "Tile"