我有下面的代码不能在GCC 4.9和GCC 5.1上编译。我似乎无法弄清楚为什么。对不起,如果这是一个noob问题,我是一种新的C++模板。作为朋友的模板嵌套私人类
template<class T>class A
{
template<class X>friend class B;
struct C {};
};
template<class X>class B
{
template<class T>friend struct A<T>::C;
};
int main()
{
A<int> a;
B<float> b;
}
编译时我收到以下错误
[email protected]# g++-49 templatefriend.cpp
templatefriend.cpp: In instantiation of âclass B<float>â:
templatefriend.cpp:38:9: required from here
templatefriend.cpp:27:9: error: âstruct A<T>::Câ is private
struct C {};
^
templatefriend.cpp:31:1: error: within this context
{
^
在那里,如果我删除
class A
{
friend class B;
class C{};
};
class B
{
friend class A::C;
};
int main()
{
A a;
B b;
}
任何帮助表示赞赏模板,或者如果这样的问题已经编译没有问题被问到,请分享链接。
对不起我的错,错的评论,整流 –
'C'的模板,因为它是'A' –
@RyanHaining我想我必须学习很多有关模板中:P –