You can get Boost at http://www.boost.org/
The particular file I am curious is this: http://www.boost.org/boost/any.hpp
*(any_cast<int>(const_cast<any *>(&x)));
Only problem is... How can I find out what int is? I want to overload the << operator so that you can cout it without knowing the datatype. Is there a way to use it without specifying <int> ?
Cause if you have this:
Code:
int main()
{
any x(10);
//x.getdata();
cout << *(any_cast<int>(const_cast<any *>(&x)));
cout << endl;
x = 'a';
//x.getdata();
cout << *(any_cast<int>(const_cast<any *>(&x)));
cout << endl;
return 0;
}
Also, you can use
cout << any_cast<int>(x);
instead of using the const_cast.
You get a run time error because it isn't an int, but a char.
Would you need to have a "getint()" and a "getchar()" etc function for every datatype that you want?
So is "held" actually stored in a way you can get it without knowing the type?