我想使用带有流成员的类。
我的代码如下所示:
//! pushes a Source and InputFilters into a filtering_istream
class FilterChain {
public:
//! create an empty FilterChain
FilterChain(){
init();
}
private:
//! the stream to connect Source and InputFilters together
io::filtering_istream* m_filteringStream;
//! stream to use by other classes
std::istream* m_stream;
void init(){
std::streambuf* streamBuffer = m_filteringStream->rdbuf();
m_stream->rdbuf(streamBuffer);
}
};
我收到一条错误消息,表明 std::basic_istream 构造函数受到保护:
/usr/include/c++/4.8.1/istream:在成员函数`void FilterChain::init()'中:/usr/include/c++/4.8.1/istream:606:7:错误:`std::basic_istream <_CharT, _Traits>::basic_istream() [with _CharT = char; _Traits = std::char_traits]' 受保护
我也尝试了流引用,但这导致了同样的错误。任何想法如何解决这一问题?
编辑1:
谢谢,我用这样的新 init() 修复了它:
void init(){
std::streambuf* streamBuffer = m_filteringStream->rdbuf();
m_stream = new std::istream(streamBuffer);
}