80.3k views
1 vote
After the initial construction of both, what does the following code invoke?

a) Default constructor
b) Copy constructor
c) Assignment operator
d) None of the above

User Jkhadka
by
7.8k points

1 Answer

0 votes

Final answer:

The code will invoke either the copy constructor or the assignment operator, depending on whether a new object is being created as a copy of another, or an existing object is being assigned the value of another.

Step-by-step explanation:

After the initial construction of both, the code will invoke the copy constructor if it is a statement like Object newObj(existingObj), where existingObj is an instance of a class and newObj is being created as a copy of existingObj. Alternatively, it will invoke the assignment operator if the statement is similar to existingObj = newObj, where both objects have already been constructed, and you are assigning the value of one to another.

User Befzz
by
8.6k points