Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 checking if object is member of
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pavol




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: 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.
wtd




PostPosted: 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) { ... }
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: