Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is a constructor initializer list and when we use
constructor initializer list?

Answers were Sorted based on User's Feedback



What is a constructor initializer list and when we use constructor initializer list? ..

Answer / deep

There is couple special case when you need mandatory
constructor initialization list.

a. To initialise a const
b. To initialise a reference

Is This Answer Correct ?    12 Yes 1 No

What is a constructor initializer list and when we use constructor initializer list? ..

Answer / sachin mahajan

Main purpose of the contstuctor is to initialize the data
members with some valid values. This can be done in two ways
class MyClass{
int I,J;
public:
MyClass(int i,int j )
{
I=i;J=j;
}
};
Above the most common way to initialize data members .Other
way is
MyClass(int i,int j):I(i),J(j)
{
}
i(0),j(0) is the initialization list.

Constuctor Initialization list is used when we want to pass
some data to the constructor the parent class.
Below is the example:
class Parent
{
int I;
public:
Parent(int i)
{
I=i;
}
};
class Child:public Parent
{
int J;
public:
Child(int i,int j):Parent(i),J(j)
{

}

};

main()
{
Child c(1,2);
//now 1 is passed to parent and 2 is passed to Child
}

Is This Answer Correct ?    12 Yes 5 No

What is a constructor initializer list and when we use constructor initializer list? ..

Answer / mahesh

The main use of constructor is to initialize object.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C++ General Interview Questions

How do we balance an AVL Tree in C++?

0 Answers   Impetus,


How is an Abstract Base Class(ABC) related to an "Abstract Data Type" (ADT)

2 Answers  


What are abstract data types in c++?

0 Answers  


what is the order of initialization for data?

10 Answers   Amazon, TCS, Wipro,


How is memory managed in C++?

2 Answers  


Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;

0 Answers  


When to use “const” reference arguments in a function?

0 Answers  


how many trys can we write in one class

3 Answers   Cap Gemini,


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

0 Answers  


Write a program using GUI concept for the scheduling algorithms in Operating system like SJF,FCFS etc..

0 Answers  


Explain the difference between overloading and overriding?

0 Answers  


What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

0 Answers  


Categories