Recently while going through someone code written in C++, I saw that he declares the function in very different way, The function he defines is shown below:
struct Node{
Node* next;
Node* prev;
int value;
int key;
Node(Node* p, Node* n, int k, int val):prev(p),next(n),key(k),value(val){};
Node(int k, int val):prev(NULL),next(NULL),key(k),value(val){};
};
So in this code
Node(Node* p, Node* n, int k, int val):prev(p),next(n),key(k),value(val){};
I am not able to understand this line, like how he defines the function in this way because we define function having return type,arguments and then body(In case of constructors we don't have return type). I am not able to understand how this line of code works. Please anyone explain me this in detailed.
In this code I am not able to understand how he uses the constructor like he defines it using colon:
and also see how he initialize the variable value
just convert it to a function without having body value(val){}
Thanks in advance.