问题是
“创建一个指向Reader对象的至少四个指针的数组。使用New运算符可以创建指向派生类对象的至少三个指针,并将它们分配给数组”
The reader is the base class. The fantasyReader, horrorReader, misteryReader, and scienceReader are derived class.
我必须阅读Reader.txt
"""""""""""contents""""""""""""
David
0 <-Mystery category
John
1 <-Horror category
Mark
2 <-Science category
Sarah
3 <-fantasyReader
"""""""""""""""end"""""""""""""""""""
我拥有的
enum {HORROR, MYSTERY, SICENCE, FANTASY};
int main(void)
{
Reader *obj[10];
ifstream reader_file;
int category =0;
string name;
string number;
int counter = 0;
if(reader_file.is_open())
{
while( getline(reader_file, name,
) &&
getline(reader_file, number,
))
{
switch(category)
{
case FANTASY:
obj[counter++] = new fantasyReader(name);
break;
case MYSTERY:
obj[counter++] = new mysteryReader(name);
break
case HORROR:
obj[counter++] = new horrorReader(name);
break;
case SCIENCE:
obj[counter++] = new scienceReader(name);
break;
}
}
}
}
我不确定我的代码是否回答了上面的问题。