You can't know which derived type to construct before you read the line that names it. What you can do is have a function that reads the first line, then delegates the rest to the appropriate subclass constructor.
list<Homes*> home;
string str;
while(ins >> str)
{
switch(str)
{
Homes *tmp;
case "Brickhome":
tmp = new Brickhome(ins);
break;
case "LogCabin":
tmp = new LogCabin(ins);
break;
case "Castle":
tmp = new Castle(ins);
break;
default:
throw("unknown type of home");
}
home.push_back(tmp);
}
Note that the subclasses must have a sensible way of knowing when to stop (e.g. Brickhome
must either know how many attributes it has, or know that "LogCabin" cannot be one of its attributes, and must therefore be put back into the stream before the constructor terminates).