[英]code compiles on Sun Studio but gives error on gcc
I have this code which gets compiles using Sun Studio but gives error in g++ 我有这个代码,使用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&)
As you can see in above error message that DBReader class has operator>> which takes std::string by reference and UtlString class is derived from std::string so static_cast should not be a problem but still compiler complains that there is no matching method. 正如您在上面的错误消息中看到的那样,DBReader类有运算符>>它通过引用获取std :: string而UtlString类是从std :: string派生的,所以static_cast不应该是一个问题,但仍然编译器抱怨没有匹配的方法。 Also can anyone tell me how to remove â charachter appearing in error message. 也有人可以告诉我如何删除出现在错误消息中的字符串。
Thanks 谢谢
You may build an temporary std::string from the UtlString. 您可以从UtlString构建一个临时的std :: string。
std::string tmp(value);
if(_state == DBMRan){
_reader >> tmp;
}
That should at least work on both compilers. 这应该至少适用于两个编译器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.