-
typecast overloading
Hopefully most of us know about things like static_cast... I'm not referring to those though..
say you have a class called "any"
And you want to be able to do this:
(int)someany;
or
int(someany);
is there a way to write this, or will C++ not let you create them for the built in types?
-
Why would you want to cast a class to an int? If you want an integer representation of a class, just make a member function or operator for the class that gives you an integer. I don't think that casting a class to an int is possible, not sure though. You can cast an int* to a class* with reinterpret_cast<>
-
My thinking is then you could pass an object to a function that wouldn't normally expect it