相关疑难解决方法(0)

为什么decltype没有看到成员声明?

试图编译这个简单的类:

#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看不到班级成员?

c++ c++11

27
推荐指数
2
解决办法
1288
查看次数

标签 统计

c++ ×1

c++11 ×1