Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. STL container of multiple types

STL container of multiple types

Scheduled Pinned Locked Moved C / C++ / MFC
c++dockerdata-structuresquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Todd Smith
    wrote on last edited by
    #1

    I need to hold an array of values of varialbe type such as int's float's string's etc. The array will be created at compile time. Any ideas?

    C N T 3 Replies Last reply
    0
    • T Todd Smith

      I need to hold an array of values of varialbe type such as int's float's string's etc. The array will be created at compile time. Any ideas?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Can you use VARIANT ? Christian #include "std_disclaimer.h" The careful application of terror is also a form of communication. Eagles may soar, but weasels don't get sucked into jet engines.

      T 1 Reply Last reply
      0
      • C Christian Graus

        Can you use VARIANT ? Christian #include "std_disclaimer.h" The careful application of terror is also a form of communication. Eagles may soar, but weasels don't get sucked into jet engines.

        T Offline
        T Offline
        Todd Smith
        wrote on last edited by
        #3

        I dunno. Is VARIANT compatible with string and iostreams? Can you say VARIANT somevar; somevar >> aniostream; aniostream << somevar;

        S 1 Reply Last reply
        0
        • T Todd Smith

          I dunno. Is VARIANT compatible with string and iostreams? Can you say VARIANT somevar; somevar >> aniostream; aniostream << somevar;

          S Offline
          S Offline
          Shankar Chandra Bose
          wrote on last edited by
          #4

          Hmmm, off the top of my head, may I suggest you try creating your own struct/class that holds a string, float, int, etc. Infact, this is how VARIANTs in VB/COM are implemented under the hood anyway. Then use this struct/class in your maps, lists, and other STL structures. You might want to experiment with unions as well. You could also take a look at MFC's COleVariant, and see if you can bend it to meet your needs (this is mostly used for database related stuff, but am sure you can use it for other needs as well).

          1 Reply Last reply
          0
          • T Todd Smith

            I need to hold an array of values of varialbe type such as int's float's string's etc. The array will be created at compile time. Any ideas?

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            If I understand you want one place to hold variables of different type(long, int, string, etc.). The only way I'm aware of is to use VARIANT, but this has its draw backs. Using a VARIANT adds bulk and slows down your code. If you don't need to support VB or scripting languages then don't use VARIANT. Is this for MFC? Then you can COleVariant << and >> operators, otherwise I don't beleive _variant_t has that capability. Can you use seperate containers for each type? list, list, etc.

            P 1 Reply Last reply
            0
            • N Not Active

              If I understand you want one place to hold variables of different type(long, int, string, etc.). The only way I'm aware of is to use VARIANT, but this has its draw backs. Using a VARIANT adds bulk and slows down your code. If you don't need to support VB or scripting languages then don't use VARIANT. Is this for MFC? Then you can COleVariant << and >> operators, otherwise I don't beleive _variant_t has that capability. Can you use seperate containers for each type? list, list, etc.

              P Offline
              P Offline
              Philippe Mori
              wrote on last edited by
              #6

              If this is what you want to do, I suggest that you uses a wrapper class like COleVariant or _variant_t (or maybe your own class). At least those class properly handle memory managment and help a with initialisation. The one to uses depends on your needs. If you need more functionaly, then you should create your own class that may derive or embed a COleVariant or _variant_t. _variant_t class may be a bit easier to uses since it allows conversion from the variant to another type:

              _variant_t v(3.2);
              double d = v;

              but it does not support writting to CArchive... You may also uses _variant_t for the container and create ColeVariant object at place you need extra functionaly. Philippe Mori

              1 Reply Last reply
              0
              • T Todd Smith

                I need to hold an array of values of varialbe type such as int's float's string's etc. The array will be created at compile time. Any ideas?

                T Offline
                T Offline
                Todd Smith
                wrote on last edited by
                #7

                I think this will work http://www.boost.org/libs/any/index.html gonna try it out...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups