0

親クラスから派生したクラスをファイルに書き込んでいる場合、どのクラスをファイルから読み込んでいるかを判断するにはどうすればよいですか?

基本的に、 、 、 の 3 つの派生クラスがDerivedAありDerivedBますDerivedC。ファイルに書き込むとき、私はこれを行いました:

DerivedA
   attribute1
   attribute2
   attribute9
DerivedB
   attribute5
   attribute6
DerivedC
   attribute4
   attribute7

現在どのクラスを読んでいるかを判断するために if ステートメントを設定するにはどうすればよいですか?

編集:

各家に特定の異なる属性を持つ家のリストを作成しています。

list<Homes*> home;
Homes *tmp;
while(ins>>tmp)
{//determine which home it is
  tmp=new ***//depends on which derived class it is;
}

私のデータファイルでは、次のようになります。

Brickhome
solar panels
3 bathrooms
Spiral Staircase
LogCabin
gravel driveway
fireplace
Castle
10 butlers
1 moat

どの家を作成する必要があるかを判断する方法が必要です。

4

1 に答える 1