Thread: What's " BETTER " ?

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001

    What's " BETTER " ?

    What are the PRO's/CON's of doing the following
    in relation to each other

           STL container of MyClass* such as std::vector<MyClass*>
           STL container of MyClass such as std::vector<MyClass>

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    If you need to use different containers to store exactly the same elements then a containers of MyClass*'s are necessary, and they'll probably be faster in some respects as the STL containers often copy elements from one location to another. The cost of copying a pointer will probably be less than having MyClass's copy constructor called.

    However, containers of MyClass*'s can be trickier as you always have to ensure that the pointers point to valid locations and you'll probably have to manage memory yourself unless you implement a smart pointer.

Popular pages Recent additions subscribe to a feed