473,837 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

"Timothy Madden" <ba****@rmv.spa m.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"

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

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

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.


Jul 22 '05 #2

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

Similar topics

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 dynamic (on the put side)? Do you put stuff in it once and then get from it until it's empty or do you put stuff in it a bit at a time? Or, can you do both? Also, does the queue actually get smaller as the threads feed from it or does it stay the...
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!
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. New tasks would added to the 'bottom' of the queue and completed records would disappear off the top. Any idea how to implement this in Access 97?
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 Queue. FIFOQueue(): A First In First Out Queue. PriorityQueue(lt): Queue where items are sorted by lt, (default <).
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 horribly stuck on even how I actually could write it. Has somebody done that before? And when yes, how is the best way to implement it? Thanks, Thomas
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 5 threads processing workitems. As soon as the number of threads gets below five, more workitems can be queued. This goes on until the stack of workitems is fully processed. Not sure if that is what one would call a "Thread Pump".
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
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) { }
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 Queue& Q)}
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 declerations.... #include <queue> #include <vector> #include <string> class database { queue<delayTP> delayThrouput;
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.