no ABC's in STL containers..

Discussion in 'C++' started by Sean, Jul 10, 2003.

  1. Sean

    Sean Guest

    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
     
    Sean, Jul 10, 2003
    #1
    1. Advertising

  2. "Sean" <> wrote in message
    news:3M5Pa.100889$...
    >
    > 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
     
    John Harrison, Jul 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    947
    Jiong Feng
    Nov 19, 2003
  2. Bruce Sam
    Replies:
    15
    Views:
    8,069
    John C. Bollinger
    Nov 19, 2004
  3. vsgdp

    ABC inheriting from ABC

    vsgdp, Sep 24, 2005, in forum: C++
    Replies:
    1
    Views:
    331
    vsgdp
    Sep 24, 2005
  4. Gunter Henriksen

    x.abc vs x['abc']

    Gunter Henriksen, May 13, 2009, in forum: Python
    Replies:
    1
    Views:
    381
    alex23
    May 15, 2009
  5. Replies:
    4
    Views:
    173
Loading...

Share This Page