STL container of multiple types
-
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?
-
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?
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.
-
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.
I dunno. Is VARIANT compatible with string and iostreams? Can you say VARIANT somevar; somevar >> aniostream; aniostream << somevar;
-
I dunno. Is VARIANT compatible with string and iostreams? Can you say VARIANT somevar; somevar >> aniostream; aniostream << somevar;
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).
-
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?
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.
-
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.
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
-
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?
I think this will work http://www.boost.org/libs/any/index.html gonna try it out...