stream - C++ How to initialize a std::istream* although constructor is protected -


i want use class stream-members.

my code looks that:

//! pushes source , inputfilters filtering_istream class filterchain { public:     //! create empty filterchain     filterchain(){         init();     }  private:     //! stream connect source , inputfilters     io::filtering_istream* m_filteringstream;     //! stream use other classes     std::istream* m_stream;      void init(){         std::streambuf* streambuffer = m_filteringstream->rdbuf();         m_stream->rdbuf(streambuffer);     } }; 

i error message std::basic_istream constructor protected:

/usr/include/c++/4.8.1/istream: in member function `void filterchain::init()': /usr/include/c++/4.8.1/istream:606:7: error: `std::basic_istream<_chart, _traits>::basic_istream() [with _chart = char; _traits = std::char_traits]' protected

i tried stream references caused same error. ideas how fix this?

edit 1:

thx sehe fixed new init() that:

void init(){         std::streambuf* streambuffer = m_filteringstream->rdbuf();         m_stream = new std::istream(streambuffer);     } 

your code shown doesn't contain problem @ all.

the problem trying default-construct istream object somewhere (not in question code).

you need at least buffer initialize with:

std::filebuf  m_dummy; std::istream  m_stream(&dummy); 

now, can reassign rdbuf did. see also, e.g. how can switch between fstream files without closing them (simultaneous output files) - c++

update dietmar confirmed, pass nullptr streambuf* argument:

std::istream  m_stream(nullptr); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -