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_Private_Inner Classes - Fatal编程技术网

C++ 从非成员模板函数访问私有内部类类型

C++ 从非成员模板函数访问私有内部类类型,c++,templates,private,inner-classes,C++,Templates,Private,Inner Classes,考虑以下代码: #include <iostream> using namespace std; class Outer { struct Inner { int num; }; public: static Inner GetInner() { return Inner{-101}; } }; // void func1(Outer::Inner inner) { // [1] Does not compile as exp

考虑以下代码:

#include <iostream>
using namespace std;

class Outer {
    struct Inner {
        int num;    
    };

public:
 static Inner GetInner() {
    return Inner{-101};
}
};

// void func1(Outer::Inner inner) {  // [1] Does not compile as expected
//  cout << inner.num <<endl;
//}

template <typename Dummy>
void func2(Outer::Inner inner, Dummy = Dummy()) {
    cout << inner.num << endl;
}


int main() {
    // func1(Outer::GetInner()); // [2] does not compile as expected 
    func2<int>(Outer::GetInner()); // [3] How does this compile? 
                                   // Outer::Inner should not be accessible
                                   // from outside Outer
    return 0;
}
我在ubuntu上使用g++4.8.2,但我在gcc-4.9.2(www.ideone.com)上也看到了这一点

您可以在此处尝试代码:

我明白了

错误1错误C2248:“外部::内部”:无法访问类“外部”中声明的私有结构


使用Visual Studio 2013更新4。因此,这是编译器中的一个问题。

看起来像一个g++错误,您同时找到了答案吗?对我来说,这不应该是法律法规。谢谢!看起来叮当有点问题。
prog.cpp: In function 'void func1(Outer::Inner)':
prog.cpp:5:9: error: 'struct Outer::Inner' is private
  struct Inner {
         ^
prog.cpp:15:19: error: within this context
 void func1(Outer::Inner inner) {
               ^