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
我需要確定需要創建該回家的路。
你能提供一些實際的示例代碼來幫助說明你在說什麼嗎? – nhgrif
已添加到原始帖子,謝謝 – Walter
我想我不清楚屬性可能是什麼?您包含的示例代碼與您實際存在疑問的部分無關。 – nhgrif