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??
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!
MSDN <- Programmers Haven!
You could just use an unsigned short array, and then ignore the extra range if you don't need it.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Or create a templated Array class?
MSDN <- Programmers Haven!
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.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
thanx for the help....
i think template should be feasible as it will save memory space for me....