no ABC's in STL containers..

S

Sean

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/~kremer/STL/1024x768/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
 
J

John Harrison

Sean said:
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/~kremer/STL/1024x768/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top