0

I was expecting it should call either copy or move constructor but neither of them called.

#include <iostream>
using namespace std;

class A
{
public:
    A()
    {
        std::cout << "A" << std::endl;
    }

    A(A &)
    {
        std::cout << "C" << std::endl;
    }

    A(A &&obj)
    {
        std::cout << "M" << std::endl;
    }
};

A get()
{
    A obj;
    return obj;
}

int main()
{
    A obj = get();
    return 0;
}

Output

A
WhozCraig
  • 63,603
  • 10
  • 71
  • 134
Mahesh
  • 1,115
  • 1
  • 6
  • 19

0 Answers0