C++0x - a few doubts

This is a discussion on C++0x - a few doubts within the C++ Programming forums, part of the General Programming Boards category; Ok... I will have to digest this more. It seemed a good idea. I did feel the need a few ...

  1. #31
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Posts
    7,317
    >> 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
    Location
    Chch, NZ
    Posts
    597
    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
    Code:
    #include <vector>
    
    class Thing {};
    
    class MyThingVector : private std::vector<Thing>
    {
    public:
        // 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
    Code:
    #include <vector>
    
    class Thing {};
    
    class MyThingVector
    {
    public:
        // expose some vector functionality
        inline size_t size(void) const { return m_vec.size(); }
    
        // some custom functionality
        void AddThing(Thing& t);
    private:
        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
    Posts
    2,879
    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?
    Yes.
    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.

Page 3 of 3 FirstFirst 123
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, 09:47 PM
  2. More questions (relating to global doubts)
    By Jorl17 in forum C++ Programming
    Replies: 29
    Last Post: 12-03-2008, 10: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, 03:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21