class Investment { ... }; // root class of hierarchy of
// investment types
Investment* createInvestment(); // return ptr to dynamically allocated
// object in the Investment hierarchy;
// the caller must delete it
// (parameters omitted for simplicity)
void f()
{
Investment *pInv = createInvestment(); // call factory function
... // use pInv
delete pInv; // release object
}
In the book, the author gives the example code like the one shown above. This is the first time I've seen this line:
Investment* createInvestment(); // call factory function
Is this function written inside the class definition or outside? What are the requirements in the class definition to make that line functional? i.e. Would you need a definition like this? Is this even a valid definition?
class Investment {
public:
Investment* createInvestment(){
return ptr;
};
private:
Investment* ptr;
};