朋友拥有自己的类模板和其他模板参数
Friend with own class template with other template parameter
是否可以将自己的类模板与其他模板参数声明为好友?
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;
相关文章:
- C++ 默认参数使用其他参数
- lambda 作为接受其他参数的参数的初始化顺序
- 了解'this'或其他参数是否为右值
- 递归回文检查,不使用向量、大小或其他参数
- 模板模板参数用作其他参数的默认值
- 可以移动构造函数以除班级本身以外的其他参数
- 在传递其他参数时在 C++ 中重载运算符
- 具有可变参数模板参数的部分专用化,后跟其他参数
- 在参数包中获取函数指针的返回类型,并将其保存为与其他参数连接的元组
- 委托构造函数和默认参数,具体取决于其他参数
- 在boost :: static_visitor中operator()中的其他参数
- 带有映射参数的函数需要其他参数
- 是否有一个WinAPI可以从带有可选空格和其他参数的命令行获取文件名
- 后面跟有其他参数的函数参数包的模板参数推导
- 将字符串(或任何其他参数)传递到QWidget构造函数
- 使用其他参数的默认参数
- 如何设置依赖于其他参数的参数默认值
- C++获取具有其他参数的构造函数的初始值设定项列表
- C++函数模板,函数作为参数,取决于其他参数
- 使用 boost::bind 但允许传递任何其他参数