1
Object::Object(int x);
Object::~Object;
Object::Object(const &object);

when calling:

Object o=13;

I think it split 2 steps;

Object temp(13);
Object o=temp;

So it will call copy constructor,but I print the info: there is no any copy constructor be called.

So can somebody help to explain it? I think it should has no relations with NRVO or RVO.

jiafu
  • 6,338
  • 12
  • 49
  • 73

1 Answers1

0

There is elision of the copy constructor in your example.

From the c++ Standard:

This elision of copy/move operations, called copy elision, is permitted in the following circumstances (which may be combined to eliminate multiple copies):

...

β€” when a temporary class object that has not been bound to a reference (12.2) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move

Also there is an important note:

[ Note: This two-stage overload resolution must be performed regardless of whether copy elision will occur. It determines the constructor to be called if elision is not performed, and the selected constructor must be accessible even if the call is elided. β€”end note ]

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335