What is called member intializer?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is called member intializer??

10th May 2021, 9:54 AM
K S Mirthun
K S Mirthun - avatar
5 Answers
+ 1
It is a way to initialize the members in class. Given a class Student with 1 string member 'name' and 1 int member 'age'. You can use the following constructor to initialize members: Student(string s, int n): name(s), age(a) {} Note that const member and reference member can only be initialized in member initializer-list. The following is invalid. class A { private: const int x; public: A() {x = 42;} //Error here };
10th May 2021, 11:03 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Member is alternative for attribute ( I mean can we call the member as attribute)??
10th May 2021, 11:54 AM
K S Mirthun
K S Mirthun - avatar
0
What is mean reference member??
10th May 2021, 11:55 AM
K S Mirthun
K S Mirthun - avatar
0
K S Mirthun reference member is a member declared reference. You declare a reference variable with with: int b = 42; int& a = b; //reference variable cout << a; //output 42 Reference is like pointer, but it doesn't store the address. It stores a reference of the variable. The reference can't changed once it's initialized. And what do you mean by attributes in class? Can you give an example?
10th May 2021, 12:02 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Thanks bro 😊
10th May 2021, 12:04 PM
K S Mirthun
K S Mirthun - avatar