homogeneous container

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johan

    #1

    homogeneous container

    Hi,

    Where can I find coding example in C++ for homogeneous container.

    John


  • Phlip

    #2
    Re: homogeneous container

    Johan wrote:
    [color=blue]
    > Where can I find coding example in C++ for homogeneous container.[/color]

    std::deque<int>

    There - they integers, so they are all the same: homo!

    Nonono I'm not calling you "homo" - that's what "homo" means: same!

    Oh, you meant a "heterogeno us container". That's: different!

    If you need a hetero container of primitives - int, float, string - you need
    a VARIANT type. Check out your nearest non-Standard library, such as Qt, or
    boost.org, or COM. They provide types such as QVariant, Any, or _variant_t,
    which hold many kinds of primitives, and handles to ORB objects.

    Put them all in bed together like this:

    std::deque<QVar iant>

    Next, if you need to store many types derived from a base class, you need a
    collection of pointers to it:

    std::deque<Base *>

    Now you can push the addresses of objects of classes derived from Base into
    the collection.

    That won't delete any heap objects when the deque disappears, so see
    www.boost.org for adapters such as shared_ptr<>, and for more code samples
    than you thought possible.

    [BTW there were several other wicked puns available here, so I deserve
    credit for the superhuman effort of avoiding them;]

    --
    Phlip



    Comment

    • Mike Wahler

      #3
      Re: homogeneous container


      "Johan" <me@knoware.n l> wrote in message
      news:10n27i3qtc bb4c4@corp.supe rnews.com...[color=blue]
      > Hi,
      >
      > Where can I find coding example in C++ for homogeneous container.[/color]

      All of the C++ standard library container types are
      homogenous by definition.

      Coding example:

      #include <vector>

      int main()
      {
      std::vector<int > container;
      return 0;
      }

      -Mike


      Comment

      Working...