Computer Science Canada

checking if object is member of

Author:  pavol [ Thu Nov 27, 2008 1:00 pm ]
Post subject:  checking if object is member of

Hi to all. I have a function that takes an ostream object as an argument. I want to be able to pass to it either cout or a file stream. Is there any way I can distinguish between the two. For example:
code:
ostream &out
if(out is a member of ofstream)
    //do file stuff
else
    //do terminal stuff

Author:  md [ Thu Nov 27, 2008 5:10 pm ]
Post subject:  RE:checking if object is member of

Passing an additional flag is probably the easiest way, otherwise...


Well... you could use typeid() (see: http://www.cplusplus.com/doc/tutorial/typecasting.html). But really, why do you want to do something different? It's an output stream... just output whatever.

Author:  wtd [ Fri Nov 28, 2008 12:36 am ]
Post subject:  RE:checking if object is member of

code:
<some_type> foo(std::ostream& out) { ... }

<some_type> foo(std::ofstream& out) { ... }


: