
-----------------------------------
pavol
Thu Nov 27, 2008 1:00 pm

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:
ostream &out
if(out is a member of ofstream)
    //do file stuff
else
    //do terminal stuff


-----------------------------------
md
Thu Nov 27, 2008 5:10 pm

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.

-----------------------------------
wtd
Fri Nov 28, 2008 12:36 am

RE:checking if object is member of
-----------------------------------
 foo(std::ostream& out) { ... }

 foo(std::ofstream& out) { ... }
