繁体   English   中英

代码在Sun Studio上编译但在gcc上出错

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM