#include <iostream>
class Test {
public:
Test(const int& i)
{
std::cout << "Direct" << std::endl;
}
Test(const Test& t)
{
std::cout << "Copy" << std::endl;
}
};
int main()
{
Test test = 1;
return 0;
}
This program(compiled in C++11) will only output Direct
, but the Test test = 1;
means implicit convert 1 to a Test and then copy the result to test
, I expected it output both of Direct
and Copy
, could anyone explain it?