可变参数构造函数是否应该隐藏隐式生成的构造函数,即默认构造函数和复制构造函数?
struct Foo
{
template<typename... Args> Foo(Args&&... x)
{
std::cout << "inside the variadic constructor\n";
}
};
int main()
{
Foo a;
Foo b(a);
}
不知何故,我希望在阅读此答案后不会打印任何内容,但它会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);
}
同样,两行都被打印出来。