Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Queue class for my own struct

Status
Not open for further replies.

Korach

Programmer
Jun 2, 2003
303
IL
Hi,

I want to set a queue of pixel coordinates.
the struct is:
struct point
{
public int x;
public int y;
public int basex;
public int basey;
};
if I use q.Enqueue(pnt) it works fine, but this line:
pnt = q.Dequeue;
make the compile error:
"Cannot implicitly convert type 'object' to 'Interface.point'"
(Interface is my namespace)
Is there any way to convert type object to my struct?

Thanks
 
You need to cast it to the correct type:
Code:
pnt = (point)q.Dequeue;
Since this is tiresome to do everywhere where you're going to be pulling an item off the queue, it might be worthwhile to create a new class that encapsulates a Queue and provides Enqueue and Dequeue methods that return your point type:
Code:
class PointQueue
{
   private Queue m_Queue;

   // Constructor
   PointQueue()
   {
      m_Queue = new Queue();
   }

   public void Enqueue(point pnt)
   {
      m_Queue.Enqueue(pnt.ToObject());
   }

   public point Dequeue()
   {
      return (point)m_Queue.Dequeue();
   }
}
That way you'll never have to worry about a rectangle object ending up on your queue that's only supposed to hold points.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top