Answer to Question #180498 in C++ for Aditya Pandey

Question #180498

Explain the difference between 

constructor and initializer list. With program.


1
Expert's answer
2021-04-12T13:35:07-0400

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){
  }
  };

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS