错误C2512:'std :: basic_ostream< _Elem,_Traits>' :没有适当的默认构造函数只与Visual Studio可用 [英] error C2512: 'std::basic_ostream<_Elem,_Traits>' : no appropriate default constructor available with Visual Studio only
问题描述
我问这个问题,因为我有点无奈:这个错误只发生在Visual Studio,GCC编译它没有错误,甚至警告。因为这是一些可移植代码我正在寻找一个解决方案与两个编译器(最好的情况下没有平台依赖 ifdefs
)。
<$ p $ <$> MyObject:public Socket,public std :: ostream
code>
code> std :: ostream $> c $ c>是 std :: basic_ostream< char>
的类型别名。 std :: basic_ostream< char>
的构造函数需要一个指向输出流所关联的流缓冲器的指针。您必须提供一个。 构造函数的签名如下:
explicit basic_ostream(std :: basic_streambuf< CharT,Traits> * sb);
您的类构造函数应如下所示:
class MyObject:public Socket,public std :: ostream
{
MyObject(/ * ... * /)
:
std :: ostream(/ *提供一个ptr到这里的流缓冲区/ *)
// ...
{
// ...
}
};
另请参阅此以供参考。
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 code I'm looking for a solution that works with both compilers (and in best case with no platform-dependent ifdefs
).
error C2512: 'std::basic_ostream<_Elem,_Traits>' : no appropriate default constructor available
happens while constructing an object of type MyObject that is defined as
class MyObject : public Socket, public std::ostream
What special ostream
parameters are expected by VS here?
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.
这篇关于错误C2512:'std :: basic_ostream< _Elem,_Traits>' :没有适当的默认构造函数只与Visual Studio可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!