What is default constructor?
Ans- Constructor with no arguments or all the arguments has default values.
What is copy constructor?
Ans- Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.
for example:
Boo Obj1(10); // calling Boo constructor
Boo Obj2(Obj1); // calling boo copy constructor
Boo Obj2 = Obj1;// calling boo copy constructor
When are copy constructors called?
Ans- Copy constructors are called in following cases:
a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object
What is assignment operator?
Ans- Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)
What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one.??
Ans- default ctor
copy ctor
assignment operator
default destructor
address operator
Ans- Constructor with no arguments or all the arguments has default values.
What is copy constructor?
Ans- Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.
for example:
Boo Obj1(10); // calling Boo constructor
Boo Obj2(Obj1); // calling boo copy constructor
Boo Obj2 = Obj1;// calling boo copy constructor
When are copy constructors called?
Ans- Copy constructors are called in following cases:
a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object
What is assignment operator?
Ans- Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)
What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don't define one.??
Ans- default ctor
copy ctor
assignment operator
default destructor
address operator
0 comments:
Post a Comment