Sayan Mukherjee
December 24th, 2002, 12:05 AM
Hi,
In the following code I am overloading the member
access operator '->' . But when I actually make a
member function call using '->', the message inside
the overloaded function does not show. The method
call works alright as if the operator was never
overloaded.
#include <iostream.h>
#include <string>
// ComplexNumber: class definition
class ComplexNumber
{
private:
long X;
long Y;
public:
void Assign(long pX, long pY)
{
X = pX;
Y = pY;
}
void Show(void)
{
cout << X << "+" << Y <<"i" << endl;
}
ComplexNumber* operator->(void)
{
cout << "Overloaded -> ..." << endl;
return this;
}
};
// main()
int main(int argc, char* argv[])
{
ComplexNumber *pC1 = new ComplexNumber;
pC1->Assign(8, 10);
pC1->Show();
delete pC1;
return 0;
}
In the following code I am overloading the member
access operator '->' . But when I actually make a
member function call using '->', the message inside
the overloaded function does not show. The method
call works alright as if the operator was never
overloaded.
#include <iostream.h>
#include <string>
// ComplexNumber: class definition
class ComplexNumber
{
private:
long X;
long Y;
public:
void Assign(long pX, long pY)
{
X = pX;
Y = pY;
}
void Show(void)
{
cout << X << "+" << Y <<"i" << endl;
}
ComplexNumber* operator->(void)
{
cout << "Overloaded -> ..." << endl;
return this;
}
};
// main()
int main(int argc, char* argv[])
{
ComplexNumber *pC1 = new ComplexNumber;
pC1->Assign(8, 10);
pC1->Show();
delete pC1;
return 0;
}