"Sean" <se******@rogers.com> wrote in message
news:3M********************@news04.bloor.is.net.ca ble.rogers.com...
Recently tried to make a vector of a classe that contained a pure
virtual member. It didn't work. I've since found a little bit of
information including one possible solution:
http://pages.cpsc.ucalgary.ca/~kreme...x768/ref2.html
However the author mentions that the solution provided is not very
efficient. Was wondering if anyone here has solved this problem for
themselves in an efficient manner?
Cheers,
Sean
A vector of reference counted smart pointers is the usual solution. Seems
much more straightforward than the slightly wierd Ref2 class you quote. When
you use a vector for instance, much of the copying of element will happen
when the vector reallocates itself. In this case there is absolutely no need
to clone objects as Ref2 will. I think Ref2 is actually trying to solve a
different problem, that you have to use pointers to get poylmorphism in C++.
The Ref2 classs give value semantics to a pointer, at the cost of cloning
that pointer on each copy.
john