c++ - How to pass ostream objects? -
i have struct this
struct x{ ostream out; x() : out(cout) {} ... };
and noticed have define out & correctly pass cout default parameter: ostream &out; don't know why , don't know if there other possibilities keeping ostream without &. furthermore, when try set
x x; ofstream out; x.out = out;
the compiler found many errors... want able set x::out cout or ofstream. how it?
ostreams cannot passed value. have pass reference or pointer.
if want ability make x.out
refer different streams during lifetime, make pointer. otherwise make reference.
Comments
Post a Comment