cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'|



  • Wenn ich dieses einfache Beispiel kompiliere, bekomme ich folgenden Fehler:

    #include "../rapidxml/rapidxml.hpp"
    #include <fstream>
    
    int main()
    {
        rapidxml::xml_document<> doc;
        std::ofstream file("text.xml");
        file << doc;
    }
    

    ||=== Build: Debug in sample (compiler: GNU GCC Compiler) ===|
    /src/main.cpp||In function 'int main()':|
    /src/main.cpp|8|error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'|
    /usr/include/c++/4.9.2/ostream|602|note: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = rapidxml::xml_document<char>]'|
    ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

    Codeblocks zeigt auf diesen Teil von ostream:

    #if __cplusplus >= 201103L
      /**
       *  @brief  Generic inserter for rvalue stream
       *  @param  __os  An input stream.
       *  @param  __x  A reference to the object being inserted.
       *  @return  os
       *
       *  This is just a forwarding function to allow insertion to
       *  rvalue streams since they won't bind to the inserter functions
       *  that take an lvalue reference.
      */
      template<typename _CharT, typename _Traits, typename _Tp>
        inline basic_ostream<_CharT, _Traits>&
    ->    operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
        { return (__os << __x); }
    #endif // C++11
    

    Ich verstehe den Fehler nicht, in jedem Beispiel von RapidXml wird das Dokument so gespeichert. Kann doc nicht in eine rvalue umgewandelt werden?



  • Use print() function or operator <<, which are defined in rapidxml_print.hpp header.


Anmelden zum Antworten