I am learning c++ for the first time, In a basic linked list if node* next is a simple pointer then if I dereference it, It should give me the value at the next node but it doesnt, instead I have to access it through int data. I just want to know why it does that in a linked list and not when I dereference it for a single variable say int x=5.
Heres, the code
#include <iostream>
using namespace std;
class node {
public:
int data;
node* next;
node(int data){
this->data = data;
}
};
int main(){
node* nodeA = new node(25);
node* nodeB = new node(30);
node* nodeC = new node(40);
nodeA->next = nodeB;
nodeB->next = nodeC;
node x = *(nodeA->next); /* If I replace this line with int x = *(nodeA->next) it gives me error saying - no suitable function conversion from node to int exists */
cout<<"node A: "<< nodeA->data <<" : " << (*nodeA->next).data <<endl;
cout<<"nodeB: "<< &nodeB->data<<" : "<< nodeB->next <<endl;
cout<<"ans: "<< x <<endl; // ERROR HERE SAYS - NO OPERATOR "<<" MATCHES THESE OPERANDS
return 0;
}