Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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+;中模板B类中声明为私有字段的模板类A访问结构+;? 有以下C++原始代码: 模板 甲级{ 私人: //在这里,我想访问B::SomeStruct以在类A中创建SomeStruct字段 }; 模板 B类{ 私人: 模板 A级朋友; 结构SomeStruct{ 使某些字段无效; }; };_C++_Oop_Member Access - Fatal编程技术网

如何从c+;中模板B类中声明为私有字段的模板类A访问结构+;? 有以下C++原始代码: 模板 甲级{ 私人: //在这里,我想访问B::SomeStruct以在类A中创建SomeStruct字段 }; 模板 B类{ 私人: 模板 A级朋友; 结构SomeStruct{ 使某些字段无效; }; };

如何从c+;中模板B类中声明为私有字段的模板类A访问结构+;? 有以下C++原始代码: 模板 甲级{ 私人: //在这里,我想访问B::SomeStruct以在类A中创建SomeStruct字段 }; 模板 B类{ 私人: 模板 A级朋友; 结构SomeStruct{ 使某些字段无效; }; };,c++,oop,member-access,C++,Oop,Member Access,在类A中,我想创建一个类型为SomeStruct-struct的字段,该字段在类B中声明为私有成员。这可能吗 限制: 禁止创建全局结构,可同时访问a类和B类 禁止在B类中创建任何公共字段 这将是一种方式。所有B:s与所有A:s成为朋友,A拥有B::SomeStruct成员: template<typename T> class B { private: template<typename Tp> friend class A; struct So

在类A中,我想创建一个类型为
SomeStruct
-struct的字段,该字段在类B中声明为私有成员。这可能吗

限制:

  • 禁止创建全局结构,可同时访问a类和B类
  • 禁止在B类中创建任何公共字段

  • 这将是一种方式。所有
    B
    :s与所有
    A
    :s成为朋友,
    A
    拥有
    B::SomeStruct
    成员:

    template<typename T>
    class B {
    private:
        template<typename Tp>
        friend class A;
    
        struct SomeStruct {};
    };
    
    template<typename T>
    class A {
    private:
        // 'typename' prior to dependent type name 'B<T>::SomeStruct':
        typename B<T>::SomeStruct ss;
    };
    
    模板
    B类{
    私人:
    模板
    A级朋友;
    struct SomeStruct{};
    };
    模板
    甲级{
    私人:
    //依赖类型名称“B::SomeStruct”之前的“typename”:
    typename B::SomeStruct ss;
    };
    
    哪个
    B::SomeStruct
    B::SomeStruct
    ?@TedLyngmo,B::SomeStruct,实际上。@TedLyngmo,我只想在类中创建一个SomeStruct字段,我认为(希望)模板专门化并不重要。请查看我下面的答案,看看这是否符合您的要求。