Skip navigation

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: