Operator for casting a class to void*
-
Hi, i would like to know hot to implement an operator to cast a class to void*. I thought of overloading operator (), but i don't know how to proceed (as i didn't find anything on the web). Any ideas? thanks!!
The following example overloads the + operator to add two complex numbers and returns the result. // operator_overloading.cpp // compile with: /EHsc #include using namespace std; class Complex { public: Complex( double r, double i ) : re(r), im(i) {} Complex operator+( Complex &other ); void Display( ) { cout << re << ", " << im << endl; } private: double re, im; }; // Operator overloaded using a member function Complex Complex::operator+( Complex &other ) { return Complex( re + other.re, im + other.im ); } int main() { Complex a = Complex( 1.2, 3.4 ); Complex b = Complex( 5.6, 7.8 ); Complex c = Complex( 0.0, 0.0 ); c = a + b; c.Display(); }
-
Hi, i would like to know hot to implement an operator to cast a class to void*. I thought of overloading operator (), but i don't know how to proceed (as i didn't find anything on the web). Any ideas? thanks!!
Something like:
class MyClass
{
public:
operator LPVOID() const
{
return ???;
}
};
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Something like:
class MyClass
{
public:
operator LPVOID() const
{
return ???;
}
};
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Since you did not tell us anything about your class, I obviously don't know what that method needs to return.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen