warning C4172: returning address of local variable or temporary
清泛原创
warning C4172: returning address of local variable or temporary
//返回单词出现的行号set
const set<int> & TextQuery::RunQuery(string word) const
{
map< string,set<int> >::const_iterator it = m_mapWordLine.find(word);
if(it != m_mapWordLine.end())
return it->second;
else
return set<int>();//emptyset
}
解决方法:愿意是返回set对象的const引用以减轻复制set对象的负担,但是这里返回空的set对象的局部引用是错误的,c++ primer 原文采用的方法是返回set对象,不使用引用,这也是一种解决方法。另外使用std::vector<std::string>::size_type 比int型的set好。
上一篇:error C2664:...No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
下一篇:error C2440: 'initializing' : cannot convert from 'char *' to 'const class std::basic_string