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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -