ポリモーフィズムに問題があります。これらの基本クラスを設定しました。メソッドは後で追加されますが、これらのクラスからさまざまなデータメンバーにアクセスできるようにします。
class square
{
public:
bool canBeBought;
string name;
};
class property : public square
{
public:
int rent;
int colour;
int cost;
bool bought;
};
class specialSquare : public square
{
private:
public:
};
これが私が呼んでいるコードです
square* properties[23];
for(int i = 0; i < 23; i++)
{
if(propertyStrings.at(i).substr(0,8) == "Property")
{
istringstream ss(propertyStrings.at(i).substr(11,21));
string temp;
properties[i] = new property;
while(!ss.eof())
{
properties[i]->bought = false;
properties[i]->name = propertyStrings.at(i).substr(0,11);
cout << "Name: " << properties[i]->name << endl;
ss >> temp;
properties[i]->cost = atoi(temp.c_str());
cout << "Cost: "<< properties[i]->cost << endl;
ss >> temp;
properties[i]->rent = atoi(temp.c_str());
cout << "Rent: "<< properties[i]->rent << endl;
ss >> temp;
properties[i]->colour = atoi(temp.c_str());
cout << "Colour: "<< properties[i]->colour << endl << endl;
break;
}
}
}
私の問題は、name変数がsquareクラスにあるため、正常に機能しますが、プロパティクラスのデータメンバーが認識されないことです。私の目的は、プロパティクラスとspecialSquareクラスの1つの配列にすべての正方形のデータを格納することでした。これにより、プログラムの後半で作業が簡単になります。