可变构造函数是否应该隐藏隐式生成的构造函数,即默认构造函数和复制构造函数?
struct Foo
{
template<typename... Args> Foo(Args&&... x)
{
std::cout << "inside the variadic constructor\n";
}
};
int main()
{
Foo a;
Foo b(a);
}
Run Code Online (Sandbox Code Playgroud)
不知何故,我希望在阅读这个答案之后不打印任何内容,但它会inside the variadic constructor在g ++ 4.5.0上打印两次:(这种行为是否正确?
它也没有可变参数模板:
struct Foo
{
Foo()
{
std::cout << "inside the nullary constructor\n";
}
template<typename A> Foo(A&& x)
{
std::cout << "inside the unary constructor\n";
}
};
int main()
{
Foo a;
Foo b(a);
}
Run Code Online (Sandbox Code Playgroud)
同样,两行都打印出来.