In the book Generic Programming and the STL (Chinese edition), it says:
X x = X()
will call the copy constructor.
It seems a little weird to me. And I write a test program like this
#include <iostream>
class Test {
public:
Test() {
std::cout << "This is ctor\n";
}
Test(const Test&) {
std::cout << "This is copy-ctor\n";
}
};
int main(int argc, char** argv)
{
Test t = Test();
return 0;
}
The output is "This is ctor". ok, now I'm confused, which is right?