why is {} placed after member initializer list in c++, although it is supposed to be empty ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why is {} placed after member initializer list in c++, although it is supposed to be empty ?

class myclass{ public: myclass(int a, int b, int c) :var1(a),var2(b),var3(c) { // these curly braces. } //these curly braces. private: int var1,var2,var3; };

12th Jul 2019, 3:23 PM
Snigdh
Snigdh - avatar
1 Answer
+ 6
It's because when you define a function, it needs a body, the curly brackets is used to define the function body, even though it's empty
12th Jul 2019, 3:36 PM
Agent_I
Agent_I - avatar