The initializer list is used to initialize data members of the class. The syntax of the initializer list begins with a colon(:) and then each variable along with its value separated by a comma.
Note: The initializer list does not end in a semicolon.
Let see an example to understand the initializer list in C++,
In the below code, the member variable value is initialized by the initializer list.
#include<iostream>
using namespace std;
class Demo
{
public:
// initialization List
Demo(int value):value(value)
{
cout << "Value is " << value;
}
private:
int value;
};
int main()
{
Demo obj(10);
return 0;
}
Answer:
The initializer list is used to initialize data members of the class. The syntax of the initializer list begins with a colon(:) and then each variable along with its value separated by a comma.
Note: The initializer list does not end in a semicolon.
Let see an example to understand the initializer list in C++,
In the below code, the member variable value is initialized by the initializer list.
Output: Value is 10
need an explanation for this answer? contact us directly to get an explanation for this answer