[英]Visual studio to gcc, code compiles well in gcc but gives std::badalloc error at runtime
[英]code compiles on Sun Studio but gives error on gcc
我有這個代碼,使用Sun Studio進行編譯,但在g ++中出錯
DBManager & DBManager::operator >> (UtlString &value)
{
//## begin DBManager::operator>>%921890065.body preserve=yes
if(_state == DBMRan){
_reader >> static_cast<std::string>(value);
}
return *this;
//## end DBManager::operator>>%921890065.body
}
DBManager.cpp:263: error: no match for âoperator>>â in â((DBManager*)this)->DBManager::_reader >> std::basic_string<char, std::char_traits<char>, std::allocator<char> >(((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(&((jda::UtlString*)value)->jda::UtlString::<anonymous>))))â
DBReader.h:50: note: candidates are: virtual DBReader& DBReader::operator>>(char&)
DBReader.h:51: note: virtual DBReader& DBReader::operator>>(unsigned char&)
DBReader.h:52: note: virtual DBReader& DBReader::operator>>(short int&)
DBReader.h:53: note: virtual DBReader& DBReader::operator>>(short unsigned int&)
DBReader.h:54: note: virtual DBReader& DBReader::operator>>(int&)
DBReader.h:55: note: virtual DBReader& DBReader::operator>>(unsigned int&)
DBReader.h:56: note: virtual DBReader& DBReader::operator>>(long int&)
DBReader.h:57: note: virtual DBReader& DBReader::operator>>(long long int&)
DBReader.h:58: note: virtual DBReader& DBReader::operator>>(long unsigned int&)
DBReader.h:59: note: virtual DBReader& DBReader::operator>>(long long unsigned int&)
DBReader.h:60: note: virtual DBReader& DBReader::operator>>(float&)
DBReader.h:61: note: virtual DBReader& DBReader::operator>>(double&)
DBReader.h:62: note: virtual DBReader& DBReader::operator>>(DBDateTime&)
DBReader.h:63: note: virtual DBReader& DBReader::operator>>(DBBlob&)
DBReader.h:64: note: virtual DBReader& DBReader::operator>>(std::string&)
DBReader.h:65: note: virtual DBReader& DBReader::operator>>(DBNullIndicator&)
otlv4.h:35416: note: otl_connect& operator>>(otl_connect&, otl_stream&)
正如您在上面的錯誤消息中看到的那樣,DBReader類有運算符>>它通過引用獲取std :: string而UtlString類是從std :: string派生的,所以static_cast不應該是一個問題,但仍然編譯器抱怨沒有匹配的方法。 也有人可以告訴我如何刪除出現在錯誤消息中的字符串。
謝謝
您可以從UtlString構建一個臨時的std :: string。
std::string tmp(value);
if(_state == DBMRan){
_reader >> tmp;
}
這應該至少適用於兩個編譯器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.