In which of thd the given situation constructor be invoked?
Answers
Answered by
9
Answer:
Explanation:
when an existing object is assigned an object of it own class
MyClass A,B;
A = new MyClass();
B=A; //copy constructor called
if a functions receives as argument, passed by value, an object of a class
void foo(MyClass a);
foo(a); //copy constructor invoked
when a function returns (by value) an object of the class
MyClass foo ()
{
MyClass temp;
....
return temp; //copy constructor called
}
Please feel free to correct any mistakes I've made; but I am more curious if there are any other situations in which the copy constructor is called.
Answered by
0
The object is initialised as soon as it is created by calling its function Object().
- An object's function Object() constructor is called automatically when it is created. Constructors have no return types, not even void. A virtual function Object() constructor is impossible.
- Similar to a method, a function Object() constructor is called when constructing a class object and is typically used to initialise the instance variables of the class. The constructors share the class name and lack a return type.
- In general, it is utilised to initialise new objects' data members. In C++, the class or structure name serves as the name of the function Object() constructor . When creating an object, the function Object() constructor is called. It creates the values, i.e., supplies the object with data, which is why it is referred to as a function Object() constructor .
#SPJ2
Similar questions