Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generic type container without using void* ptr

Status
Not open for further replies.

tryfekid

Programmer
Aug 16, 2001
9
US
I need to know if there's a way to store generic types without using the void* pointer. I've seen ways of using void* pointer to hold the generic type but I'm looking for a different approach. Here's what I mean:

struct var_info
{
string var_name;
string data_type;
(numerical type here) value;
};

"value" can be any numerical type: int, short, long, double, float, etc... I need to do this because I want to put this info into a parameterized container such as a vector, or hash table. Please let me know if this is possible and any help is appreciated.
 
how bout

typedef byte char;
union GenericType
{
byte b
short s;
int i;
long l;
float f;
double d;
};

struct var_info
{
string var_name;
string data_type;
GenericType value;
};

that may work for you... you just have to make sure you set it properly because if you set an int, and compare it as a float you will not get the desired result.

Matt


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top