3
是否可以将其他模板参数作为朋友申报自己的班级模板?带其他模板参数的自己班级模板的朋友
template<class T, class... Ts>
class A {
template<class U> friend class A<U, Ts...>; //compile error - C3772 'A<U>': invalid friend template declaration
};
是否可以将其他模板参数作为朋友申报自己的班级模板?带其他模板参数的自己班级模板的朋友
template<class T, class... Ts>
class A {
template<class U> friend class A<U, Ts...>; //compile error - C3772 'A<U>': invalid friend template declaration
};
template<class T, class... Ts>
class A {
template<class U, class... Us> friend class A; //here you go
};
无需经过A
类模板的部分特化不能被宣布为朋友指定模板参数。只有(完整)专业化或整个班级模板。如果你真的需要交好所有U
专业化,你需要去亲近整个模板:
template<class U, class... Us> friend class A;
有有介绍(我们)的新参数包的问题。我只想要A的第一个参数是不同的。这也可能吗? – Philinator
@Philinator我很确定这是不可能在当前的标准。 – xinaiz