Hello. I'm currently making a program that deals with a priorityQueue and inheritence/polymorphism.

Student -> undergrad -> coop_student
or
student -> grad

Now, the queue takes in the data and just puts it in a linked list and gives it a priority. That way, there are 3 queues and we dequeue from the first going to last.
Here are the snippets that have the problem.

Note: I was told that I don't need an operator=, but if I do, I can add one.


priorityQueue.cpp:30: error: no match for ‘operator=’ in ‘n->node::data = theStudent’

void priorityQueue::enqueue( student * theStudent, int priority )
{
	if( priority > 3 || priority < 1 )
		return;
	priority--;
	node *n = new node;
	n->data=theStudent;
	n->next=NULL;
	node *p;

main1.cpp:32: error: invalid conversion from ‘int’ to ‘student*’
main1.cpp:39: error: invalid conversion from ‘int’ to ‘student*’
Both of these redirect to the dequeue

nt priorityQueue::dequeue()
{
	for(int i=0; i<3; i++)
	{
	if(queues[i] != NULL)
	{
		int returnnum;	
		node *temp;
		temp = queues[i];
		if(queues[i]->next != NULL)
			{
			queues[i]=queues[i]->next;
			returnnum = temp->data;
			delete temp;
			return returnnum;
			}
		else
			{
			queues[i]=NULL;
			returnnum = temp->data;
			delete temp;
			return returnnum;
			}
		
	}
	}
	return 0;
}

it looks like the data member of node is of type int. Make sure data is of type student*

Okay I fixed all of that. Thank you! Now a problem lies with enqueue. I'll show.

The error I get is

/tmp/ccokqXJy.o:(.rodata._ZTI4grad[typeinfo for grad]+0x8): undefined reference to `typeinfo for student'
/tmp/ccokqXJy.o:(.rodata._ZTI9undergrad[typeinfo for undergrad]+0x8): undefined reference to `typeinfo for student'
/tmp/ccILXRDu.o: In function `student':
/home/rimojenkins/Programs/Assignment6/student.h:8: undefined reference to `vtable for student'
/tmp/ccILXRDu.o: In function `~student':
/home/rimojenkins/Programs/Assignment6/student.h:8: undefined reference to `vtable for student'
collect2: ld returned 1 exit status
make: *** [main1] Error 1

Oh the node class is now

using namespace std;
class node{
	friend class priorityQueue;
	student *data;
	node* next;

public:
	node();
	~node();
};

Here is enqueue

/* Enqueues by checking priority and downsizing if it meets qualifications.
Makes a new node and give it the number. Make it's next Null. If queueus[priority] is null, then we just assign it n. If it's not, we loop to the end of the linked list and assign that n
*/
void priorityQueue::enqueue( student *theStudent, int priority )
{
	if( priority > 3 || priority < 1 )
		return;
	priority--;
	node *n;
	n->data=theStudent; //messes up here
	n->next=NULL;
	node *p;

	if(queues[priority]==NULL)
	{
		queues[priority] = n;
	}
	else
	{
	for(p = queues[priority]; p->next != NULL; p=p->next)
	{}
	p->next=n;
	}
}

Here is student.h

class student{
protected: 
	string name;
	int ID;
	double gpa;
	int credits;
public:
	void setName(string );
	void setID(int);
	void setGPA(double);
	void setCredits(int);

	string getName();
	int getID();
	double getGPA();
	int getCredits();

	virtual bool canGraduate();
	virtual void print();
};

First issue i see is on line 9 of your priorityQueue::enqueue function. You declare a node pointer, but never instantiate it with the new keyword. Try node *n = new node();

Same for node *p

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.