xtofl
xtofl

Reputation: 41519

g++4.4: iostream move semantics

I was trying to create a move constructor for a class that aggregates an ostringstream. However, I keep running into

/usr/include/c++/4.4.5/bits/ios_base.h:790: error: 
  ‘std::ios_base::ios_base(const std::ios_base&)’ is private

This is the simplest code I could come up with

struct C {
    C(){ s << "start! "; }
    C(C&& c): s( std::move(c.s) ){ s << " moved "; }
    std::ostringstream s;
private:
    C(const C&);
};

C f() { return C(); }

int main(){
    C c=f();
    c.s << "aha";
    std::cout << c.s.str() << std::endl;
}

Is the iostreams library intended to implement move semantics? Or is it merely g++4.4.5 that doesn't support them yet?

Upvotes: 1

Views: 446

Answers (1)

Bo Persson
Bo Persson

Reputation: 92341

The iostreams are movable, but only if you have C++11 support. Gcc 4.4 is probably not enough for that.

The private base class copy constructor is there exactly to make the classes non-copyable (but possibly movable).

Upvotes: 3

Related Questions