Some way of making a function accept any data type?

Started by
11 comments, last by johnnyBravo 20 years, 2 months ago
Of perhaps boost::dynamic_any?

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
... but templates are the way, using boost::any or not.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
quote:Original post by johnnyBravo
i want to do this because i am storing integers, floats etc into a file, and iam making a class wrapper over the fstream


This should work :

class FileWrapper{  fstream out;  template<class T>  void write(const T & t)  {     out << t;  }};


This only works if your compiler supports member function templates (don't know if MSVC6 does this, gcc does and MSVC7+ should do it to). Off course for every datatype you wan't to 'write' you need to have an operator << defined which works on std::fstream's.

[edited by - George2 on February 29, 2004 2:03:58 PM]

[edited by - George2 on February 29, 2004 2:04:38 PM]
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon

This topic is closed to new replies.

Advertisement