I defined a class with both copy and move constructors. The copy constructor seems to work fine but when I try to invoke the move constructor it doesn't work.
#include <iostream>
class A{
public:
A() = default;
A(A& a){
std::cout << "Copy constructor." << std::endl;
};
A(A&& a){
std::cout << "Move constructor." << std::endl;
};
};
int main(int argc, char *argv[]){
auto a = A(A());
std::cout << "here" << std::endl;
auto b = A(a);
return 0;
}
I expect the auto a = A(A());
should invoke move constructor because its input (A()
) is an rvalue
. But the output is this:
[amirreza@localhost tmp]$ ./a.out
here
Copy constructor.
Is my assumption wrong?
I'm using gcc
version 10.3.1
without explicitly specifying the c++ version.