我最近升级到GCC 4.4(MinGW的TDM版本)和现在后续的代码产生这些警告:C++ GCC4.4警告:数组下标是以上数组界限
在成员函数“无效控制台::打印(常量的std :: string &)':
警告:数组下标是以上数组界限
下面的代码:
void Console::print(const std::string& str) {
std::string newLine(str);
if(newLine.size() > MAX_LINE_LENGTH) {
sf::Uint32 stringSize = newLine.size();
for(sf::Uint32 insertPos = MAX_LINE_LENGTH;
insertPos < stringSize; insertPos += MAX_LINE_LENGTH) {
newLine.insert(insertPos, "\n");
}
}
StringList tokens;
boost::split(tokens, newLine, boost::is_any_of("\n"));
for(StringList::iterator it = tokens.begin();
it != tokens.end(); ++it) {
addLine(*it);
}
}
任何想法?
这是正在做的优化...
而且它似乎是这条线,这是造成它:
boost::split(tokens, newLine, boost::is_any_of("\n"));
是啊,我发现它,它是boost :: is_any_of()的参数,通过将它包装在一个字符串()构造函数中,警告消失,谢谢大家的帮助:)
boost::split(tokens, newLine, boost::is_any_of(string("\n")));
推测编译器也给出了错误的行号?请通过评论在您的代码中注明。 – 2009-07-22 22:03:59