Some of you may remember my question about structs yesterday. Well I having trouble creating my system for the tiles.
I came up with this but it doesnt work. The program crashes everytime I try to run the program.
Code:
#ifndef CLASS_HPP
#define CLASS_HPP
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
#include <vector>
#include <memory>
const int MAX_MAP_SIZE = 256;
struct Tiles
{
bool Walkable;
bool Trigger;
bool RunScript;
char Symbol;
std::string ScriptFile;
short TriggerNumber;
};
class X_Map
{
public:
X_Map();
~X_Map();
bool NewMap(const std::string& names, short x_size, short y_size);
bool LoadMap();
bool SaveMap();
long GetMapSize();
protected:
Tiles* MapTiles[256][256];
};
class MapMgr : public X_Map
{
public:
MapMgr();
~MapMgr();
void gotoxy(int xpos, int ypos);
bool GetWalkableStatus(short x, short y);
void ChangeWalkableStatus(bool status, short x, short y);
char GetTileSymbol();
void SetTileSymbol(char tile, short x, short y);
bool GetTriggerStatus(short x, short y);
void ChangeTriggerStatus(bool status, short x, short y);
void ChangeTriggerNumber(short trig_num, short x, short y);
bool GetScriptStatus(short x, short y);
void ChangeScriptStatus(bool status, short x, short y);
void SetScriptFile(const char* scriptfile);
};
#endif
and when I try to do this... it gives these errors..
Code:
C:\C++Projects\Test\class.hpp:31: error: `new' cannot appear in a constant-expression
C:\C++Projects\Test\class.hpp:31: error: ISO C++ forbids initialization of member `MapTiles'
C:\C++Projects\Test\class.hpp:31: error: making `MapTiles' static
C:\C++Projects\Test\class.hpp:31: error: invalid in-class initialization of static data member of non-integral type `Tiles*'
:: === Build finished: 4 errors, 0 warnings ===
Code:
class X_Map
{
public:
X_Map();
~X_Map();
bool NewMap(const std::string& names, short x_size, short y_size);
bool LoadMap();
bool SaveMap();
long GetMapSize();
protected:
Tiles* MapTiles = new Tiles[256][256];
};
I really am lost on ideas, so I came here as a last resort. I greatly appreciate any assistance.