C++ 11一个成员变量
什么迭代,使用基于范围for循环中,在一个std ::载体,其是类的一个成员的代码?我我试过以下几个版本:
struct Thingy {
typedef std::vector<int> V;
V::iterator begin() {
return ids.begin();
}
V::iterator end() {
return ids.end();
}
private:
V ids;
};
// This give error in VS2013
auto t = new Thingy; // std::make_unique()
for (auto& i: t) {
// ...
}
// ERROR: error C3312: no callable 'begin' function found for type 'Thingy *'
// ERROR: error C3312: no callable 'end' function found for type 'Thingy *'
它适用于普通对象,而不是指针。 – chris