[英](Simple) constructors in variadic template classes
构造函数和副本构造函数将如何查找该可变参数模板类?
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;
}
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;
};
模板类中, X
为一种装置, X<Head, Tail...>
并且所有X
具有不同的模板的参数是不同的类型,所以的复制构造X<A,B>
将不匹配X<B,A>
。
演示: http : //ideone.com/V6g35
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.