Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板嵌套私有类作为朋友_C++_Templates_Gcc - Fatal编程技术网

C++ 模板嵌套私有类作为朋友

C++ 模板嵌套私有类作为朋友,c++,templates,gcc,C++,Templates,Gcc,我有以下代码没有在GCC4.9和GCC5.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

我有以下代码没有在GCC4.9和GCC5.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;
}

非常感谢您的帮助,或者如果您已经提出了这样的问题,请共享该链接。

在这种情况下,您从clang那里得到的警告会更有帮助:

warning: dependent nested name specifier 'A<X>::' for friend class declaration is not supported

另一种选择是使用
模板类A
B
的内部,这也会使
A::C
成为朋友。

对不起,我的错误,错误的评论,纠正了
C
是模板化的,因为它在
A
@RyanHaining的内部。我想我必须学习很多关于模板的知识:pYou关于clang是正确的,只是用clang++3.5检查一下,就得到了错误。但是我不想要依赖别人的朋友。意味着A::C和B也可以成为朋友!!
class A
{
    friend class B;
    class C{};
};

class B
{
    friend class A::C;
};

int main()
{
    A a;
    B b;
}
warning: dependent nested name specifier 'A<X>::' for friend class declaration is not supported
template <typename T> class B;

template<class T>
class A {
    friend class B<T>;  // B of the same templated type is my friend
    struct C {};
};

template<class T>
class B {
    friend struct A<T>::C; // A::C of the same templated type is my friend
};