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