Why is move constructor being called instead of copy constructor? And when I remove move constructor ,then copy constructor is called .
Used : -fno-elide-constructors to avoid copy elision
#include <iostream>
class test
{
public:
int x;
char y;
bool t;
test()
{
std::cout << " constructed" << std::endl;
}
test(test &&temp)
{
std::cout << "move constructor" << std::endl;
}
test(const test &temp)
{
std::cout << "copy constructor" << std::endl;
}
template <typename... Args>
static test create(Args... x)
{
test b(x...);
return b;
}
};
int main()
{
test z = test::create();
test v = test();
}
Output :
constructed
move constructor
move constructor
constructed
move constructor
What could be the reason for the above ?