I can't figure out notation, confused with reference and pointers. I have to put Student pointers into LinkedList. And I think I just put wrong & or *. Here what I do:
int main(){
PointerClass *p = new PointerClass();
Student *s = new Student();
p->add(s);
return 0;
}
On add
as I see error:
a reference of type “Student&” (not const-qualified) cannot be initialized
above add
is defined as this
void PointerClass::add(Student& a) {
ll.AddNode(a);
}
where ll
is:
private:
LinkedList ll;
Class LinkedList has following structure:
class LinkedList
{
private:
typedef struct node {
Student data;
node* next;
}* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
}
void LinkedList::AddNode(Student& addData) {
nodePtr n = new node;
n->next = NULL;
n->data = addData;
if (head != NULL) {
curr = head;
while (curr->next != NULL) {
curr = curr->next;
}
curr->next = n;
}
else {
head = n;
}
}