C++ 可变模板类中的(简单)构造函数
一个构造函数和一个复制构造函数如何寻找这个可变模板类C++ 可变模板类中的(简单)构造函数,c++,syntax,c++11,variadic-templates,C++,Syntax,C++11,Variadic Templates,一个构造函数和一个复制构造函数如何寻找这个可变模板类 struct A {}; struct B {}; template < typename Head, typename... Tail> struct X : public Head, public Tail... { X(int _i) : i(_i) { } // add copy constructor int i; }; template <
struct A {};
struct B {};
template < typename Head,
typename... Tail>
struct X : public Head,
public Tail...
{
X(int _i) : i(_i) { }
// add copy constructor
int i;
};
template < typename Head >
struct X<Head> { };
int main(int argc, const char *argv[])
{
X<A, B> x(5);
X<A, B> y(x);
// This must not be leagal!
// X<B, A> z(x);
return 0;
}
struct A{};
结构B{};
模板
结构X:公共主管,
公共尾巴。。。
{
X(int_i):i(_i){}
//添加复制构造函数
int i;
};
模板
结构X{};
int main(int argc,const char*argv[]
{
X(5);
xy(X);
//这一定不是法律!
//xz(X);
返回0;
}
模板
结构X:公共主管,
公共尾巴。。。
{
X(int_i):i(_i){}
//添加复制构造函数
X(constx&other):i(other.i){}
int i;
};
在模板类中,X
作为一个类型意味着X
,所有具有不同模板参数的X
都是不同的类型,因此Xtemplate
结构X:公共主管,
公共尾巴。。。
{
X(int_i):i(_i){}
//添加复制构造函数
X(constx&other):i(other.i){}
int i;
};
在模板类中,X
作为一个类型意味着X
,所有具有不同模板参数的X
都是不同的类型,因此X的复制构造函数
template < typename Head,
typename... Tail>
struct X : public Head,
public Tail...
{
X(int _i) : i(_i) { }
// add copy constructor
X(const X& other) : i(other.i) {}
int i;
};