current = queues[i];

This line of code is killing me. I am suppose to be doing a write method for an array based priority queue. However I cant seem to get the first node on the give part of the array. queues is of the Queue class which is a child of SinglyLinkedList. The array holds LinkedAQNodes which is a child of SinglyLinkedNode and PriorityQueueNode (this one is pure virtural) I can't seem to get the current pointer to take the assignment. It gives me the error can't convert Queue to Any Pointer I try. Finally, we are suppose to reuse our old object files so I can't put any kind of access method in singilyLinkedList Any ideas would be appreciated. If you want I will post the actual code, just didn't want to sling a lot of code up here unless it is actually needed.

One second thought I realized how confusing the above sounds without being to see it so here are the header files

class PriorityQueue {

    virtual bool add (ifstream& infile) = 0;
    virtual bool remove (PriorityQueueNode& highestPriority) = 0;
    virtual bool isEmpty (void) const = 0;
    virtual void write (ostream& outfile) const = 0;
    
    };

class LinkedPQNode : public PriorityQueueNode, public SinglyLinkedNode {

    public:
        LinkedPQNode (int processId, int arrivalTime, int priority, int duration);
        LinkedPQNode* getNext  () const;
        void	write (ostream& outfile) const;
        
    };

class PriorityQueueA : public PriorityQueue {

    public:
        PriorityQueueA (void);
        bool	add (ifstream& infile);
        bool	remove (PriorityQueueNode& highestPriority);
        bool	isEmpty (void) const;
        void	write (ostream& outfile) const;
        
        private:
            Queue*	queues;	// pointer to array
            int	numberOfLevels; // size of array
    };
    
    ostream& operator << (ostream& outfile, const PriorityQueueA& pQ);

class SinglyLinkedList
{
   public:
                        SinglyLinkedList
                           (void);

                        ~SinglyLinkedList
                           (void);

      bool              isEmpty
                           (void) const;

      bool              isNotEmpty
                           (void) const;

      bool              addAtHead
                           (SinglyLinkedNode* newHead);

      SinglyLinkedNode* removeFromHead
                           (void);

      bool              addAtTail
                           (SinglyLinkedNode* newTail);

      void              write
                           (ostream& outfile, char separator = ' ') const;
   protected:
      SinglyLinkedNode* head;


      SinglyLinkedNode* tail;
};

      ostream&          operator <<
                           (ostream& outfile, const SinglyLinkedList& list);



class SinglyLinkedNode : public LinkedNode
{
   public:
                        SinglyLinkedNode
                           ();
      virtual
                        ~SinglyLinkedNode
                           (void);

      void              setNext
                           (SinglyLinkedNode* newNext);

      SinglyLinkedNode* getNext
                           (void) const;
};

class LinkedNode : public Node
{
   public:
                   LinkedNode
                      (int numberOfLinks);
      virtual
                   ~LinkedNode
                      (void);
   protected:
      void         setLink
                      (int i, LinkedNode* nodeAddr);

      LinkedNode*  getLink
                      (int i) const;

      int          getNumberOfLinks
                      (void) const;
   private:
      int          numberOfLinks;


      LinkedNode** links;
};
current = queues[i];

our old object files so I can't put any kind of access method in singilyLinkedList

When reusing old code it is still permissible to extend the class
as long as the extension does not alter any existing behaviour and the method is something meaningful to the code itself.

It is helpful if you post error codes and the piece of code where the problem line is.

But first a couple of observations: the code tags have highlighted remove as a keyword and so an alternative function name might be needed.

Second for the line you are using to work current = queues[i] There has to be a definition of operator[] if this is an array this should be fine and current needs to be a compatible pointer to queues

ofstream and ifstream are funny objects and cannot necessarily be passed into a function meaningfully. It is probably a good idea to place the ifstream and ofstream inside of the function and pass in a file_name.

write can fail and should return a bool

nothing else jumps off the page immediately - the error code is probably needed and the lines where you call the queues;

I understand that old code can be added to, I'd love to just add a get head access method to SinglyLinkedList and be done with it. However, we cant use our own actual old .h and .o files we have to use our professors. So I can't really make any changes. Here is the actual write method. Once again here is the basic problem, Queue is the child of SinglyLinkedList. The queue or array of them in my case hold LinkedPQNodes, which is a child of PriorityQueueNode (pure virtual) and SinglyLinkedNode. I can't seem to point to the head of each queue. I'm getting error cant convert (class)* to Queue. Maybe there is a different approach I am missing?

void PriorityQueueA::write (ostream& outfile) const{
        LinkedPQNode* current = NULL;
        outfile << "array-based priority queue\n";
        outfile << setiosflags(ios::left) << setw (9) << "pId" << setw(9) << "arrive"
               << setw(9) << "priority" << setw(9) << "duration" << setw(9) << "next\n";
        
        for (int i = 0; i < numberOfLevels; i++){
            if (queues[i].SinglyLinkedList::isNotEmpty()){
                outfile << "level[" << i << "]\n";
                current = queues[i]; // error is here 
                while (current !=NULL){
                    current -> write(outfile);
                    //current = current -> dynamic_cast <LinkedNode*> (SinglyLinkedNode::getNext ());
                }
            }
            else {
                outfile << "level[" << i <<"]\n" << "empty\n";
            }
        }
LinkedPQNode* current = NULL;
        current = queues[i]; // error is here

It is always useful to give full error code and all the initialisation but I am fairly sure I have spotted the error

You say queues is a SinglyLinkedList singlyLinkedNode * p_sll; could point to a LinkedPQNode because it LinkedPQNode is a type of SinglyLinkedNode that is what you tell the compiler when you use inheritence

but queues is not a type of LinkedPQNode so current cannot point to it;
I suspect you meant current->function(queue[i]); But I don't know what you want to do with the line that is failing
your while loop immediately after might well fail

I suspect that current is merely the wrong type of pointer

and you mean the equivalent to:

if(0 != queue[i])
{
 queue[i]->write(outfile);
}

but wanted a pointer to do some of the work but used the wrong pointer but be aware of what I said about streams as variables!

thanks for all of the help but i just missed the obivious. Since Queues is a child of SinglyLinkedList I could just use

outfile << queues[i];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.