TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DAN CHAK
from: THOMAS MAEDER
date: 1997-05-12 21:21:00
subject: My queue (1)

DC> // This is "queue.h"
DC> template 
DC> class Queue {
DC> private:
DC>    Queue();
The previous line is the source of the second compiler error; in the 
main() function, you declare
DC>    Queue Q;
The  initialization  of  Q  requires  the  default  constructor  to be
publicly available; but as you see above, it's private.
DC>    queue* next;
DC>    static Queue* front;
DC>    static Queue* back;
I  have a lot of trouble understanding these three members (apart from
the typo). What's the purpose of declaring front and back static?
[Less than three days later :-)] Now I see what you intend to do.  You
have queue and queue element properties in one single class; this will
never work properly. 
Better   declare   a   class  Element  nested  in  class  Queue  whose
responsibility is to hold one queue element  per  instance;  move  the
info and next members to this class.
The  responsibility of the Queue class then is to manage its elements;
for this to work, declare front and back to be non-static so that each
queue has its own front and back members.
DC>    dataType info;
DC>    int length;
DC> public:
DC>    Enqueue(dataType Element);
DC>    dataType Dequeue();
DC>    int length();
DC>    // template  processAll(int (*func));
The method processAll isn't good design. Iterations through containers
are better executed using instances of a  class  specifically  written
for  that  purpose,  the  so-called iterators. If you don't understand
what I mean, just forget it for the moment.  We  can  return  to  this
topic once the other methods work like they should.
DC>    dataType operator=(dataType op2);
This should be Queue &operator=(const Queue &);
DC> };
DC> template  Queue::Queue() {
DC>    next = null;
DC>    length = 0;
DC> }
Better initialize the members in the member-initialization list:
DC> template  Queue::Enqueue(dataType Element)
DC>    if (length == 0) {
DC>       front = new dataType;
DC>       dataType = Element;
DC>       next = null;
This part leaves back uninitialized.
DC>    } else {
DC>       *back.next = new dataType;
DC>       *back.*next = Element;
DC>       back = *back.next;
DC>    }
DC>    ++length;
DC>    return 1;
DC> }
DC> template  dataType Queue::Dequeue() {
DC>    if (length == 0) return 0;
DC>    else {
DC>       dataType Element = *front;
DC>       front = *front.next;
DC>       length--;
DC>       return Element;
DC>    }
DC> }
ú  [ Continued In Next Message... ]
--- PCBoard (R) v15.22/M 25
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.