for the code snippet below, what does the colon in the line Node(int elt = 0,Node * p = NULL):data(elt),next(p){}
do exactly? From what I've searched, it seems the colon used is the inheritance syntax, but in this case, I assume Node(int elt = 0,Node * p = NULL)
is a constructor for the Node structure, and it's inheriting or perhaps accessing the data(elt)
field variable? But data
is a primitive data type, why is there a parameter "elt" inside of it?
I'll appreciate it very much if anyone can explain the concepts. Thanks.
class List{
public:
void addAt(int pos, int elt);
void delAll(int x);
private:
struct Node{
int data;
Node * next;
Node(int elt = 0,Node * p = NULL):data(elt),next(p){}
};
};