【发布时间】:2013-09-10 09:35:17
【问题描述】:
我已经好几年没有使用 C++ 了,现在我需要维护一个 C++ 项目。我有以下一段代码,它似乎可以在一个项目中编译,但不能在另一个项目中编译。
list.h
#include "mytype.h"
#include <set>
typedef std::set<MYTYPE> MYTYPE_LIST;
typedef MYTYPE_LIST::iterator MYTYPE_LIST_ITERATOR;
class LIST {
[...]
MYTYPE_LIST list;
};
list.cpp
void
LIST::somemethod(MYTYPE* requester)
{
MYTYPE_LIST_ITERATOR it;
for (it = list.begin(); it != list.end() ; it++ )
{
MYTYPE& info = (*it); // Error on this line
[...]
}
}
我正在使用 VS 2010 编译我的项目,并且在标记的行上出现以下错误:
error C2440: 'initializing' : cannot convert from 'const MYTYPE' to 'MYTYPE &'
IntelliSense: qualifiers dropped in binding reference of type "MYTYPE &" to initializer of type "const MYTYPE"
我用谷歌搜索了这些错误,据我了解,(*it) 不应该是 const(因为 'it' 不是 ::const_iterator,请参阅here),因此,我应该能够分配它到引用变量。
【问题讨论】:
标签: visual-studio-2010 visual-c++ stl