Hi all,

I'm pretty new to C++ and wondering how i might achieve the following.

I have a base class with 4 derived classes.

In my main() i call a read function as part of a user defined file class which reads blocks of text from a file until the end. The 4 derived classes each match 4 different formats of these blocks of text. However, i don't know the format until i've read the first line of each block.

What i'd like is to be able to define the read function as follows:

read( base1 objB1)

but somehow return an object (or pointer to object) of one of the derived class objects.

Instead i currently have it return a flag to the main() and then in the main i call the relevant readj which matches the 4 different formats. This is too many lines of code in the main for my liking and so i'd prefer to keep the format selection within the main read function.

Is this possible?

Further, i'd like to create an array of all the return objects, no matter their format, can i do this and preserve the derived class data (i.e. an array of pointers to the base class, but whose elements actually point to memory with the stored dervied class data?)

Thanks in advance...