D
D
Daniil Demidko2016-03-09 07:41:50
C++ / C#
Daniil Demidko, 2016-03-09 07:41:50

Copy constructor call?

struct Example
{
     Example(const int &i){}
};
Example a=1; // Вызов конструктора
Example b=a; // Вызов копирующего конструктора по умолчанию

Example c=Example(1); // Но что это?

Is it a call to a constructor with a parameter of 1 OR a call to the default copy constructor?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2016-03-09
@Daniro_San

First, a constructor call to create a temporary object, then a copy constructor call from the temporary object to the one defined on the left. But the compiler can optimize to 1 call if the copy constructor is not explicitly defined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question