-
Overloaded cast?
Hello,
Is there a way to overload the way my class is casted to another object? For example, this is my class:
Code:
class CClass1
{
public:
Class1(int num) { i = num; }
blah blah
private:
int i;
};
CClass1 c (5);
int casted = (int)c;
So in that case, i would want the 'casted' to have the value of the integer member in CClass1. Is it possible in c++?
Thanks
-
I think you do something like this, I may be wrong:
Code:
class CClass1
{
public:
Class1(int num) { i = num; }
operator int()
{
return i;
}
private:
int i;
};
CClass1 c (5);
int casted = (int)c;