473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I implement a plolimorfic queue in a type-safe manner ?


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
Jul 22 '05 #1
1 1193

"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

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Bart Nessux | last post by:
How can one view the contents of a queue? I'd like to verify that the queue has the same number of objects as the list that has been put into it. Also, should one think of a queue as static or...
16
by: newsock | last post by:
What differences between queue, deque and priority_queue? And under what situations choose one of them to use? Thanks for your help!
2
by: DuncanK (duncan (AT) mccarthy DOT co DOT nz) | last post by:
Hi there! I want to implement a 'queue' of records that are prioritised (development tasks in this case). I need to be able to 'move' the records up and down the queue to change their priority....
0
by: olsongt | last post by:
This one made me smile. From: http://aima.cs.berkeley.edu/python/utils.html#Queue class Queue: """Queue is an abstract class/interface. There are three types: Stack(): A Last In First Out...
2
by: Thomas Ploch | last post by:
Hello folks, I am having troubles with implementing a timed queue. I am using the 'Queue' module to manage several queues. But I want a timed access, i.e. only 2 fetches per second max. I am...
5
by: DC | last post by:
Hi, I need the functionality to take a workitem from a stack, execute it in a different thread, get the next item, execute it asynchronously too, and so on. But: there should never be more than...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
2
by: ecestd | last post by:
how do you implement a copy constructor for this pointer-based ADT queue #include "Queuep.h" #include <cassert> #include <new> using namespace std; Queue::Queue () : backPtr (0), frontPtr(0)...
2
by: ecestd | last post by:
how do you implement a copy constructor for this pointer-based ADT queue #include <cassert // for assert #include <new // for bad_alloc using namespace std; //private:{Queue::Queue(const...
6
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.