【发布时间】:2013-08-19 21:12:18
【问题描述】:
我是 c++ 编程的新手,我需要创建迭代器,但我遇到了循环问题(在 c++11 中),因为它无法识别元素,我解释一下:
class myclass{
std::string str;
myclass();
std::iterator<(what do i have to put here?), char, diffptr_t, char*, char&> begin(){
return str.begin();
}
}
这是读取类的方法:
void func(myclass& m){
for(char a: m){ //Here's the problem, i don't know why it doesn't work
//do function
}
任何人都可以说出哪种方法是最好的方法吗?还有什么问题???
【问题讨论】:
-
就像一个注释,std::iterator 是为了帮助实现迭代器而不是实际用作迭代器的类型。