Home > Back-end >  C virtual constructors, read from the stream to different objects of derived classes
C virtual constructors, read from the stream to different objects of derived classes

Time:10-05

In the "more effective c + +" virtual constructor that entry, found some questions:
How to implement this function
 static NLComponent * readComponent (istream& STR); 
?
Under the general description:
This is a read from the stream object function, NLcomponent * is an abstract class pointer, the function to read from the stream to different objects (object is an abstract class derived classes) and by returning a pointer to a base class of objects, finally through the pointer to use this object,
Use something like this:
 components. The push_back (readComponent (STR)); 

The definition of the components
 list 

There is a problem here, read from the stream data will need to use new to keep it down! Then the new out how much space should be?
  • Related