i need to dynamically initialize an array which is either unsigned char or unsigned short int..depending on user input... the rest of the code is data type independant..
how can i implement this??
Printable View
i need to dynamically initialize an array which is either unsigned char or unsigned short int..depending on user input... the rest of the code is data type independant..
how can i implement this??
Use if statements maybe? I can smell an assignment lurking around! :D
Why do you need to?
You could just use an unsigned short array, and then ignore the extra range if you don't need it.
Or create a templated Array class?
There are various ways to implement so-called "discriminated unions", and the Variant library from Boost is an excellent implementation. But I agree with dwks - I really don't think you need a union here.
thanx for the help....
i think template should be feasible as it will save memory space for me....