我有派生類這樣的basic_iostream:類成員初始化父類
class MyStream : public std::basic_iostream<char>,
private boost::noncopyable
{
public:
explicit MyStream(SomeUsefulData& data) :
buffer_(data),
std::basic_iostream<char>(&buffer_)
{
};
~MyStream()
{
};
private:
/// internal stream buffer
MyStreamBuffer<char> buffer_;
}; // class MyStream
當我創建它的實例,但是,我得到一個DataAbort例外。
SomeUsefulData data;
MyStream stream(data); // <- Data Abort
但如果我改變MyStream堆分配MyStreamBuffer,它工作正常:
class MyStream : public std::basic_iostream<char>,
private boost::noncopyable
{
public:
explicit MyStream(SomeUsefulData& data) :
std::basic_iostream<char>(new MyStreamBuffer<char>(data))
{
};
~MyStream()
{
delete rdbuf();
};
}; // class MyStream
這是錯誤的使用類成員初始化父類?
感謝, PaulH