如何编写最少量的代码来创建一个自定义容器,以便与Qt foreach宏一起使用?
目前我有以下代码:
template< class T >
class MyList
{
public:
class iterator
{
public:
};
class const_iterator
{
public:
inline iterator& operator++ ()
{
return *this;
}
};
};
我遇到了这个编译错误:
4>.\main.cpp(42) : error C2100: illegal indirection
4>.\main.cpp(42) : error C2440: 'initializing' : cannot convert from 'MyList<T>::const_iterator' to 'int'
4> with
4> [
4> T=int
4> ]
4> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
当我尝试编译这个代码时:
MyList<int> mylst;
foreach(int num, mylst )
qDebug() << num;