How is this usually done? Is doing it at all indictive of a design problem? If so, what is the design solution?
For example..
What is the best solution to this problem? The only solution I see is make a method likeCode:#include <list> using std::list; class AbstractSomething { public: virtual void doSomething()=0; }; public RedSomething: public AbstractSomething { // implemented doSomething(); }; class SomethingWithPokaDots { // implemented doSomething(); }; int main() { list<AbstractSomething*> somethingList; AbstractSomething* a = new SomethingWithPokaDots(); AbstractSomething* b = new RedSomething(); for (int i = 0; i < 10; i++) { somethingList.push_back(new AbstractSomething(*a)); // illegal, cannot instantiate AbstractSomething somethingList.push_back(new AbstractSomething(*b)); // likewise illegal } // delete a, b, stuff in list return 0; }
AbstractSomething* allocateCopy()=0;
in the AbstractSomething class that needs to be overridden by each subsequent class. Is there any other solution?



LinkBack URL
About LinkBacks


