【发布时间】:2011-03-18 21:09:41
【问题描述】:
请考虑以下代码:
template <typename T>
struct foo
{
template <typename S>
struct bar
{
template <typename> friend struct bar;
};
};
我希望foo<T>::bar 的所有实例都成为foo<T>::bar<S> 的任何S 的朋友。如果bar 不是嵌套模板,那么上面的语法就可以正常工作。但是当我这样做时
int main()
{
foo<int> x;
}
MSVC8 (Visual C++ 2005) 不喜欢它:
1>.\main.cpp(11) : error C3855: 'foo<T>::bar': template parameter 'S' is incompatible with the declaration
1> .\main.cpp(12) : see reference to class template instantiation 'foo<T>::bar<S>' being compiled
1> .\main.cpp(14) : see reference to class template instantiation 'foo<T>' being compiled
如果我使用编译器会给我同样的错误
template <typename> friend struct foo<T>::bar;
相反。我怎样才能达到我想要的?
编辑:我仔细检查了(这里是早上,我还没醒),这似乎是VC8 bug:
【问题讨论】:
-
似乎在我的机器上工作。相同的编译器。
-
我复制粘贴了上面的确切代码,没有包含,我复制粘贴了错误消息。
标签: c++ templates friend nested-class