How do you fix a mistake std:basic_ostream is protected?



  • I want to transfer the flow to function. When compiling, I get the following error:

    ♪ ♪ ♪ \x86_64-w64-mingw32\4.7.1\include\c++\ostream [Error] 'std:basic_ostream == sync, corrected by elderman == @elder_man

    Minimum http://ideone.com/vM3Q1c :

    #include <ostream>
    

    void function (std::ostream &s) { }

    int main()
    {
    std::ostream s;
    function(s);
    }

    How can you fix that?



  • C+++ Class std::ostreamwhich is declared as an alias for specialization of class std::basic_ostream<char>

    typedef basic_ostream<char> ostream;
    

    serves as a base class for classes std::basic_ostringstream and std::basic_ofstream:

    5 The class template specialization basic_ostream serves as a base class for class templates basic_ostringstream and basic_ofstream.

    and has the only open designer with a view

    explicit basic_iostream(basic_streambuf<charT,traits>* sb);
    

    He doesn't have a default designer, so you can't create this class object as follows:

    ostream s;
    

    I agree with you that this is the compiler's bug, because according to C+++, this class has no default designer unless the specifications of the standard for this class have been revised recently.

    I mean, this is a report of the compiler's error. clang and a message from the compiler gcc

    error: calling a protected constructor of class 'std:_1:basic_ostream'

    Uncorrect.

    MS VC+++ provides a more correct statement of error

    error C2512: 'std:basic_ostream constituent': no appropriate default constructor available

    and does not appear to declare the designer default as required in C+++.

    C+++ (17.6.5 Member functions)

    3 A call to a member function signature described in the C++ standard library behaves as if the implementation declares no additional member function signatures.

    Like I've been told, it's an old library tag. libstdc++ Since then. gcc 3.4and it can't be corrected as it breaks ABI.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2