Of perhaps boost::dynamic_any?
[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Some way of making a function accept any data type?
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement