Explain the difference between
constructor and initializer list. With program.
Constructor:
A constructor is a special non static member function of a program,which is used to initialize the object of its class type.
class Test
{
public:
Test();
Test(int x);
Test(int x, int y);
};
Member initializer list specifies the initializers for direct and virtual bases and non-static data members.
class Test
{
private:
int num;
int den;
public:
Test(int n, int d) : num(n), den(d){
}
};
Comments
Leave a comment