试图编译这个简单的类:
#include <vector>
struct M
{
// interface
auto begin() -> decltype(identities.begin())
{
return identities.begin();
}
// implementation
private:
std::vector<int> identities;
};
Run Code Online (Sandbox Code Playgroud)
导致错误:
$ g++-510 where.cpp -std=c++11
where.cpp:57:35: error: ‘struct M’ has no member named ‘identities’
auto begin() ->decltype(this->identities.begin())
^
where.cpp:57:35: error: ‘struct M’ has no member named ‘identities’
$ clang++ where.cpp -std=c++11 -Wall -pedantic -Wextra
where.cpp:57:35: error: no member named 'identities' in 'M'
auto begin() ->decltype(this->identities.begin())
~~~~ ^
Run Code Online (Sandbox Code Playgroud)
为什么decltype看不到班级成员?
我在代码下面编译错误.
struct B{
double operator()(){
return 1.0;
}
};
struct A {
auto func() -> decltype(b())
{
return b();
}
B b;
};
Run Code Online (Sandbox Code Playgroud)
但是,如果我重组A,它会编译.
gcc 4.8表示'b'未在此范围内声明.
struct A {
B b;
auto func() -> decltype(b())
{
return b();
}
};
Run Code Online (Sandbox Code Playgroud)
那么,第一个出了什么问题?