I get a warning about initializing the Zone structure's two components (Zone::ZoneCoords & Zone::ZoneMap), then an error stating "synthesized method 'Zone::Zone()' first required in World's initializer list.
Code:
#ifndef WORLD_H
#define WORLD_H
#include <vector>
#include "constants.h"
struct Coords
{
int x;
int y;
};
typedef std::vector<Coords> ZoneLookupTable;
struct Tile
{
int ID;
int Type;
};
typedef std::vector<Tile> RowVec;
typedef std::vector<RowVec> ZoneVec;
struct Zone
{
// Why does the compile require this constructor?
//Zone() : ZoneCoords(), ZoneMap() {}
Coords ZoneCoords;
ZoneVec ZoneMap;
};
typedef std::vector<Zone> Area;
class World
{
public:
World() : AreaID(1), CurrentZone(), CurrentArea(), ZoneTable(), VecZoneFileNames() {};
void Load(int ID = 1);
void Update(float x, float y);
void Save();
// Helpers
void CreateZone(float x, float y);
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
std::string GenerateZoneFilePath(float x, float y);
void LoadZones();
// Accessors
int GetID() { return AreaID; }
Zone &GetZone() { return CurrentZone; }
Area &GetArea() { return CurrentArea; }
ZoneLookupTable &GetZLT() { return ZoneTable; }
private:
int AreaID;
Zone CurrentZone;
Area CurrentArea;
ZoneLookupTable ZoneTable;
std::vector<std::string> VecZoneFileNames;
};
#endif // WORLD_H
Why does the Zone struct seem to require a constructor be defined?
I know it's because it contains other structures, but I don't know why. Wouldn't an implicity created default constructor work when I leave out my manually constructed one? I searched for answers with keywords structure and constructor, then relized I wouldn't know the answer if I saw it. Thank you for any time gurus, you make my day.
As always, go easy on me, and thanks in advance!