Hi, I was wondering if we could manually decide the type (and space) a variable could get. I mean using a void pointer and assigning to that pointer the beggining address of any type we want, or class, etc... so we could use that variable for different things depending on what we want. Hope I'm being clear, I've got this code that works now but I need to know if I can get rid of the "switch":
By getting rid of the switch, I mean I want to figure out if I could do something like this, though this doesn't work, as expected:Code:void* pointer; int type_we_want; type_we_want = 2; //for example... switch(type_we_want) { case 1: pointer = new bool; break; case 2: pointer = new char; break; case 3: pointer = new short; break; case 4: pointer = new int; break; //etc... }
Get what I'm trying to do? I would like to know if it was possible to store TYPES only in an array, (by some special way) so that then we'd get in the array at the position representing the wanted type, so it could arrive to this:Code:special_kind_of_var var[] = {bool, char, short, int}; pointer = new (var[type_we_want]);
I hope that "something" like this is possible, but if you can't see why I would do this, it could get as usefull as function pointers, when you have an application with tons of types, class, etc...Code:void* pointer; nt type_we_want = 2; special_kind_of_var var[] = {bool, char, short, int}; pointer = new (var[type_we_want]); //2 pointer = new (var[2]); //var[2]=short pointer = new short;



LinkBack URL
About LinkBacks



...
, I used only classes, so I don't believe I could use a union because some class will be small, some other big,... I can add that I do all this for a 2d game I'm making, and I have lots of differents objects so none of them is similar to others...