error C2512: 'std::basic_ostream<_Elem,_Traits>' : no appropriate default constructor available with Visual Studio only

后端 未结 1 1424
忘掉有多难
忘掉有多难 2021-01-24 23:38

I\'m asking this question because I\'m a bit helpless: this error occurs ONLY with Visual Studio, GCC compiles it without errors or even warnings. Since this is some portable co

相关标签:
1条回答
  • 2021-01-24 23:49

    std::ostream is a type alias for std::basic_ostream<char>. The constructor of std::basic_ostream<char> expects a pointer to a stream buffer to which the output stream is associated. You must provide one.

    The signature of the constructor is the following one:

     explicit basic_ostream( std::basic_streambuf<CharT, Traits>* sb );
    

    Your class constructor should look something like this:

    class MyObject : public Socket, public std::ostream
    {
        MyObject(/* ... */) 
            : 
            std::ostream(/* provide a ptr to a stream buffer here /*) 
        //  ...
        {
            // ...
        }
    };
    

    Also see this for a reference.

    0 讨论(0)
提交回复
热议问题