Hey all,
I've been programming an ISBN system of sorts and I'm a little stuck (again).
I want to output my linked list to a text file, so I setup the code like this:
void saveList(char fileName[40])
{
for ( list< Publication* >::iterator it = pubList.begin(); it != pubList.end(); it++)
{
try{
std::ofstream ouf(fileName);
if( !ouf ) throw std::ios::failure( "File Error" );
ouf<<"Publication,"<<(*it)->getPublisher()<<","<<(*it)->getIsbn();
ouf.close();
}catch( const std::exception& e){
std::cerr <<e.what()<<endl;
}
}
}
Now saving like this works alright with a small issue. I can only access the public functions of the base class object, I can't access the public functions of the derived classes. In addition I can't seem to figure out a way to identify which type of object in the list it is.
in this case I want the oustream to work like this:
if object is of type Publication, output all of publications details to a file.
else if object is of type Book output all of books details to a file.
else if type is ProceedingsBook output those details to a file.
The thing is, how exactly do I identify the object type in the list?
For now I'm writing a specific data member (and get function) identifying each type, I was just wondering if there is another way?