Hello. So I managed to create my polymorphic class creating two derived class from the same. I'd like to be able to read data from file dynamically, so I overloaded the >> operator for the base class.
I found this operation quite tricky: I can only declare base class pointers, so I think it is fine to write
std::istream& operator>>(std::istream& is, BaseClass *bc_p)
within the >> body I correctly read my data from file (checked with a debugger), creating appropriate instances of the subclasses with the new
keyword and pointing bc_p to the newly created objects. Troubles begin as I return the istream: in main the BaseClass pointer points to the "old" address and not to the new one. I thought that it could be possible to do what I mean by passing to the >> operator not bc_p, but its address (the same way I would do to return a c-style array).
It is possible (and it is meaningful) to do something like that?
What is the syntax to refer to the address of a pointer?
Otherwise, what's the way to read a mutable object from file?
Thanks in advance for help.