38
我想做到以下几点:模板朋友
template <typename T>
struct foo
{
template <typename S>
friend struct foo<S>;
private:
// ...
};
但我的编译器(VC8)电抗器就可以了:
error C3857: 'foo<T>': multiple template parameter lists are not allowed
我想有template struct foo
朋友都可能实例所有T
的foo<T>
。
我该如何做这项工作?
编辑:这
template <typename T>
struct foo
{
template <typename>
friend struct foo;
private:
// ...
};
看起来编译,但它是正确的吗?朋友和模板具有非常不自然的语法。
谢谢你的工作。是的,这是我想要的。 – 2010-07-20 17:55:17
你可以请参考章节标准在哪里定义? – 2012-03-05 18:20:28
在14.5.3.3和14.5.3.4的C++ 03中,在C++ 11中,您需要阅读14.5.4中的Friends部分 – 2014-04-04 13:37:03