[英]How to make parameterized Base a friend of Derived in CRTP?
I would like to implement the CRTP on a parameterized Base, and make Base a friend of Derived: 我想在参数化Base上实现CRTP,并让Base成为Derived的朋友:
template <template <typename> class Derived, class T>
class Base;
template <class T>
class Derived : public Base<Derived, T>
{
friend class Base<Derived, T>;
};
I have a compilation error on VS2012 with the following message: 我在VS2012上出现编译错误,并显示以下消息:
error C3200: 'Derived<T>' : invalid template argument for template parameter 'Derived', expected a class template
Thanks for your help. 谢谢你的帮助。
Try this: 尝试这个:
friend class Base<::Derived, T>;
If that doesn't work, your compiler doesn't support this form of friend declaration (it should, but what do I know), and you'll have to work around by extending the friendship to all Base instantiations. 如果这不起作用,则您的编译器不支持这种形式的友情声明(应该,但是我知道什么),并且您必须通过将友谊扩展到所有基本实例来解决。
template <template <typename> class D, class BT>
friend class Base;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.