Skip navigation

Category Archives: io

If you’ve ever tried to keep an instance of std::stringstream or another stream wrapper class as a member value in one of your own classes, you may have run across this set of friendly compiler errors:

“ios_base.h:779: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private.

iosfwd:55: error: within this context

iosfwd: In Copy Constructor ‘std::basic_stringstream…

streambuf:794: error” ‘std::basic_streambuf… is private

iosfwd:55: error: within this context

iosfwd: In Copy Constructor ‘std::basic_stringstream…”

This occurs because i/o streams cannot be copied!  You’d think they would bold that on every *stream page in the cplusplus.com/reference but sadly they don’t.  Anyway, if you want to work with streams you need to either pass around references/pointers to them or, preferably, create them on the stack as needed and let them pop off automatically.  More discussion available on StackOverflow here

crossed

Advertisements