Thread: C++0x - a few doubts

  1. #31
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Ok... I will have to digest this more. It seemed a good idea. I did feel the need a few times to build hierarchies from standard containers. Most often from std::vector. The only reason I did not was exactly the absence of dynamic binding. But truth is the item in the wish list makes no reference to virtual member functions or abstract types. Simply virtual destructors.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #32
    Registered User
    Join Date
    Jan 2005
    >> Simply think that a new library or appending OO functionality to the STL will ease many situations.

    The STL is not an OO library for the most part. It is usually extended with non-member, non-friend functions like those in <algorithm>. Appending OO functionality to the STL has the issues presented by CornedBee. Adding a new library would not be easy, since it should almost certainly work with existing code that uses the STL. I'm not saying this is a bad idea, I just don't see the need for either option.

  3. #33
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Chch, NZ
    Quote Originally Posted by Mario F.
    How many classes are there that are built around a container only to provide the container with specific usage? Now... how many classes there are that then derive from this base class? I don't know any numbers, of course. But I feel this is not outrageous.

    To be able to create hierarchies with a container as a base and to be able to redefine the container functionality, seems a natural step in a programming language that we want OO capable. Especially taking into consideration the importance the STL container objects have. Maybe not a strictly necessity, but I'm not arguing about the STL being made OO. Simply think that a new library or appending OO functionality to the STL will ease many situations.
    There are basically 2 ways to get around this. The first is to derive privately from the container
    #include <vector>
    class Thing {};
    class MyThingVector : private std::vector<Thing>
        // expose some vector functionality
        using std::vector<Thing>::size;
        using std::vector<Thing>::reserve;
        // some custom functionality
        void AddThing(Thing& t);
    this avoids the virtual destructor problem as MyThingVector cannot be deleted as a std vector.

    the other option is containment
    #include <vector>
    class Thing {};
    class MyThingVector
        // expose some vector functionality
        inline size_t size(void) const { return m_vec.size(); }
        // some custom functionality
        void AddThing(Thing& t);
        std::vector<Thing> m_vec;
    This requires you to write forwarding functions. Both methods have their pros and cons
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  4. #34
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Wow, lots of stuff has happened.
    So then what happens when you use auto for a non-const container? Would non-const iterator be assumed?
    Whoops, I forgot that functions can't differ only by return type. My premise here was that a non-const container can return either a const or non-const iterator from functions like begin(), and it's not the compiler's right to decide which. However, this isn't true (non-const containers don't return const iterators, right?), so my argument is unfounded.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubts regarding random numbers generation
    By girish1026 in forum C Programming
    Replies: 9
    Last Post: 12-31-2008, 10:47 PM
  2. More questions (relating to global doubts)
    By Jorl17 in forum C++ Programming
    Replies: 29
    Last Post: 12-03-2008, 11:40 AM
  3. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  4. Two doubts about C for my project
    By j0nnyX in forum C Programming
    Replies: 4
    Last Post: 10-11-2004, 02:31 PM
  5. doubts on scanf
    By aqua in forum C Programming
    Replies: 1
    Last Post: 10-28-2002, 04:20 AM