I have an error when compiling my code, with multidimensional array.
C:\Users\Tobi13\Desktop\Projet C++\Code\Test\Test111\map.hpp|17|error: declaration of 'levelchargement' as multidimensional array must have bounds for all dimensions except the first|
And I don't understand at all. I have searched on the internet but I didn't found anything.
The code of map.hpp
class Map{
public:
void ChargementFichiersMap();
void ChargementFichierElements();
static int widthmap, heightmap;
int floorx, floory, floorwidth, floorheight;
int wallx, wally, wallwidth, wallheight;
int tpx, tpy, tpwidth, tpheight;
char *levelchargement[][]= new char [widthmap][heightmap];
sf::IntRect wallrect, floorrect, tprect;
sf::Texture tileset;
};
map.cpp
void Map::ChargementFichiersMap()
{
ifstream fichiermap("map1.txt", ios::in);
fichiermap >> widthmap >> heightmap;
fichiermap.ignore();
char lecture;
int i=0;
int j=0;
while(fichiermap.get(lecture))
{
if(lecture==0x0A) // 0x0A est le code hexa pour le saut de ligne
{
j++;
i=0;
cout << "\n";
}
else
{
levelchargement[i][j]=lecture;
i++;
cout << lecture;
}
}
fichiermap.close();
ifstream fichiernommap("nom_map.txt", ios::in);
char nommap;
fichiernommap >> nommap;
tileset.loadFromFile(nommap);
fichiernommap.close();
}
void Map::ChargementFichierElements()
{
ifstream fichierfloor("floor.txt", ios::in);
fichierfloor >> floorx >> floory >> floorwidth >> floorheight;
floorrect(floorx, floory, floorwidth, floorheight);
fichierfloor.close();
ifstream fichierwall("wall.txt", ios::in);
fichierwall >> wallx >> wally >> wallwidth >> wallheight;
wallrect(wallx, wally, wallwidth, wallheight);
fichierwall.close();
ifstream fichiertp("tp.txt", ios::in);
fichiertp >> tpx >> tpy >> tpwidth >> tpheight;
tprect(tpx, tpy, tpwidth, tpheight);
fichiertp.close();
}
main.cpp
int main()
{
sf::RenderWindow window(sf::VideoMode(720,480), "SFML works?");
Map test;
test.ChargementFichiersMap();
test.ChargementFichierElements();
while (window.isOpen())
{
sf::Vector2f taille(32.f,32.f);
for (float y = 0; y < test.heightmap; y++)
{
for (float x = 0; x < test.widthmap; x++)
{
switch (test.*(levelchargement[int(x)][int(y)]))
{
case 'W':
{
sf::RectangleShape wall(taille);
wall.setTexture(&test.tileset);
wall.setTextureRect(test.wallrect);
wall.setPosition(x*32.f, y*32.f);
window.draw(wall);
break;
}
case ' ':
{
sf::RectangleShape floor(taille);
floor.setTexture(&test.tileset);
floor.setTextureRect(test.floorrect);
floor.setPosition(x*32.f, y*32.f);
window.draw(floor);
break;
}
case 'T':
{
sf::RectangleShape tp(taille);
tp.setTexture(&test.tileset);
tp.setTextureRect(test.tprect);
tp.setPosition(x*32.f, y*32.f);
window.draw(tp);
break;
}
default:
{
sf::RectangleShape defaut(taille);
defaut.setFillColor(sf::Color::Blue);
defaut.setPosition(x*32.f, y*32.f);
window.draw(defaut);
break;
}
}
}
}
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.display();
}
return 0;
}
The whole code is working if put without any class and all, but now I have to do it in a Object Oriented programming way. I hope you'll help me, have a good day !