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++ 函数模板中的decltype和作用域解析运算符_C++_Templates_C++11_Decltype - Fatal编程技术网

C++ 函数模板中的decltype和作用域解析运算符

C++ 函数模板中的decltype和作用域解析运算符,c++,templates,c++11,decltype,C++,Templates,C++11,Decltype,显然,以下代码没有在gcc 4.7上编译: #include <vector> struct foo { std::vector<int> x; template<typename T> void bar(T) { decltype(x)::value_type y; } }; int main() { foo f; f.bar(0); } 我知道这个问题的解决办法,但为什么不呢x这里不是

显然,以下代码没有在gcc 4.7上编译:

#include <vector>

struct foo {
    std::vector<int> x;

    template<typename T>
    void bar(T) {
        decltype(x)::value_type y;
    }
};

int main() {
    foo f;
    f.bar(0);
}

我知道这个问题的解决办法,但为什么不呢
x
这里不是一个依赖的名称,那么如果编译器已经能够自己解决这个问题,为什么我需要明确指出
decltype(x)::value\u type
是一个类型?还是我错了,
x
在这里实际上是一个从属名称?

直到有人找到关于这个的特定报告(我试着查找,我找到的最接近的是),这个。基于这些信息和我之前的怀疑,我想说这只是GCC4.7中的一个bug,在4.8中已经修复。

。这是你的大部分答案。我猜是修好了。@chris噢,该死的。我试过LWS,但好久没工作了。哦,嘿,现在又开始工作了。我喜欢Culru更好的C++,因为反馈开始实施。@克里斯:你是说,LWS?我还是很难过,是的,我也一样。
test.cpp:8:9: error: need ‘typename’ before ‘decltype (((foo*)this)->foo::x)::value_type’ because ‘decltype (((foo*)this)->foo::x)’ is a dependent scope