Why does assigning to a reference to std::ostream fail to compile?

Viewed 1088

I am using an abstract class std::ostream. There is the following reference:

std::ostream &o = std::cout; 

If any condition is met I need to initialize o so that the output will be redirected to std::cout. If not, output will be redirected to the file

if (!condition)
    o = file; //Not possible 

How to correctly write the code?

2 Answers
Related