0

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){}
  };
};
  • 1
    https://en.cppreference.com/w/cpp/language/initializer_list – UnholySheep Oct 02 '19 at 22:37
  • See [this](https://stackoverflow.com/questions/7665021/c-member-initialization-list) and [this](https://stackoverflow.com/questions/926752/why-should-i-prefer-to-use-member-initialization-list). – Paul Rooney Oct 02 '19 at 22:48

0 Answers0