if I'm overloading the type cast operator, I'm running into compile errors when an implicit conversion is needed and one can't be found. Consider the simple example where I have a wrapper class that contains a type (in this case a long long):
class my_wrapper
{
long long state;
public:
my_wrapper(long long _in) : state(_in) {}
my_wrapper& operator=(const long long rhs)
{
state = rhs;
return *this;
}
operator long long()
{
return state;
}
};
The question now is that if I want to cast in code to something else (eg a void* ... assume that I'm on 64bit for this) the following does not work without specifying two casts:
my_wrapper x1 = my_wrapper(5ll);
void* i1 = (void *) x1; // Compile Error: no suitable conversion function exists
void* i1 = (void *) (long long) x1; // Works
vs. if I had written something like:
long long i1 = 5ll;
void* i2 = (void *) i1; // Works
Not a big deal, but just curious if its possible to specify that the "operator long long()" should be used as the default if there is no other conversion.