Below is my sample program:
When I compile and run the below program I get output:
#include <iostream>
class A
{
public:
explicit A()
{
std::cout << "A CTOR\n" << std::flush;
}
~A()
{
std::cout << "A DTOR\n" << std::flush;
}
A(const A & a)
{
std::cout << "A DEEP COPY CTOR\n" << std::flush;
}
void operator = (const A & a)
{
std::cout << "A DEEP COPY = CTOR\n" << std::flush;
}
A(A && a)
{
std::cout << "A DEEP COPY MOVE CTOR\n" << std::flush;
}
void operator = (A && a)
{
std::cout << "A DEEP COPY MOVE = CTOR\n" << std::flush;
}
};
int main()
{
A a = A();
A b(A());
}
Compile and run the binary:
$ c++ -std=c++14 try47.cpp
A CTOR
A DTOR
I was expecting the A's default constructor would be called followed by copy assignment ctor in first line and move ctor for second line? But this does not seems to happen? Why? I think I am missing some basic understanding here?
Please clarify when will which CTORs will actually be called?