0

I can't figure out what constructor is used to create e:

#include <iostream>
using namespace std;

class A {

public:
A() {cout<<"DEFAULT CTOR\n";}
A(int) {cout<<"A(int) CTOR\n";}

A(const A &) {cout<<"COPY CTOR\n";}
A(A &&) {cout<<"MOVE CTOR\n";}

A & operator= (const A &) {cout<<"COPY =\n";}
A & operator= (A &&) {cout<<"MOVE =\n";}


A operator+ () {A a; cout<<"operator+\n"; return a;}



void funct () { A e(+*this); }


};

int main () {

A a;
a.funct();

}

Why is e not constructed with the copy constructor? Who is actually constructing it?

The output is:

DEFAULT CTOR
DEFAULT CTOR
operator+
Tony
  • 35
  • 1
  • 4

0 Answers0