"Timothy Madden" <ba****@rmv.spam.home.ro> wrote in message
news:30*************@uni-berlin.de...
I want to stoare in a queue values of type LPCTSTR, int, long, BYTE, WORD,
DWORD and many enum types.
Can I write such a queue in a type safe maner (idealy no casts involved) ?
Thank you
"Timothy Madden"
Romania
You can if you make a container class to hold those types of values.
One way to do it might be to create one class that has a union of variables
of each of those types. Look up the "union" keyword.
Another might be a class that has a member variable of each of those types
(not in a union), and perhaps another member that tells the user of the
class whether any given member currently holds valid data. (Alternatively,
you could just have default values for those members which your system can
deal with, such as 0.) This would allow you to actually store more than
just one data item in a single container object (but you probably don't need
that).
Another possibility would be to have a hierarchy of classes, each of which
handles a different type of internal data, all deriving from a common base
class, and then have your queue store pointers to that base class type (each
of which is new'ed with an instance of the specific sub-class you need to
use).
The problem with that last idea is finding a way to get the type of data you
want via a base-class-pointer. I think one of my first two ideas might be
simpler to implement.
-Howard