Given the following code
#include <iostream>
using namespace std;
template <typename Type>
struct Something {
Something() {
cout << "Something()" << endl;
}
template <typename SomethingType>
Something(SomethingType&&) {
cout << "Something(SomethingType&&)" << endl;
}
};
int main() {
Something<int> something_else{Something<int>{}};
auto something = Something<int>{};
Something<int>{something};
return 0;
}
I get the following output
Something()
Something()
Something(SomethingType&&)
Why is the copy constructor being resolved to the templated forwarding reference constructor but not the move constructor? I am guessing that it's because the move constructor was implicitly defined but not the copy constructor. But I am still confused after reading the cases for where the copy constructor is not implicitly defined in stack overflow.
See Question&Answers more detail:os