0
What is called member intializer??
5 Antworten
+ 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
};
0
Member is alternative for attribute ( I mean can we call the member as attribute)??
0
What is mean reference member??
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?
0
Thanks bro 😊