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

时间:2013-09-24 07:50:01

标签: c++ gcc c++11

我有这个代码使用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类具有运算符&gt;&gt;它通过引用获取std :: string,而UtlString类是从std :: string派生的,所以static_cast应该不是问题,但仍然编译器抱怨没有匹配的方法。 也有人可以告诉我如何删除出现在错误消息中的字符。

由于

1 个答案:

答案 0 :(得分:2)

您可以从UtlString构建一个临时的std :: string。

std::string tmp(value);    
if(_state == DBMRan){    
    _reader >> tmp;    
}    

这应该至少适用于两个编译器。