C++模板,部分专业化和朋友
C++ templates, partial specialization and friends
我很难让一个类与模板及其所有部分专业化成为朋友。有没有什么具体的技巧来实现这一点,或者有一些我不知道的限制?
class Y{
template<class T>
friend class X; // friends all instantiation forms of X
void a_private_func() const{}
};
template<class T>
class X{
public:
void f(Y const& y){ y.a_private_func(); }
};
template<class T>
class X<T*>{
public:
void g(Y const& y){ y.a_private_func(); }
};
Ideone上的实例。
相关文章:
- 如何使用默认参数等选择模板专业化
- 模板化建造师专业化
- 类模板的成员功能的定义在单独的TU中完全专业化
- 一位朋友将模板函数缩写为clang和gcc
- 部分专业化和嵌套模板
- 模板专业化可以进入我的.cpp吗?
- 别名模板的专业化 C++11 中没有开销的最佳替代方案
- 班级的朋友是不可接近的
- 与朋友声明相反
- 部分专业化和对标准::void_t<>的需求
- "专业化不参与超载"
- 为什么即使我声明了朋友类,我也会收到错误"无法访问类中声明的私人成员"
- 特定好友功能专业化
- 是否可以混合使用SFINAE和模板专业化?
- 类似虚拟的朋友功能?
- 为什么C++需要公共继承,忽略朋友声明,才能使动态向下工作?
- 在朋友类中使用模板
- C 朋友操作员模板专业化
- 模板类专业化和朋友类
- C++模板,部分专业化和朋友