operator overloading problem~
hi all~
i built a class which supports operator overloading, here is my code:
Code:
class Test
{
public:
Test() { a=2; b=3; };
Test operator * (Test t);
Test operator [] (Test t);
void trace() { std::cout << a << "\t" << b << "\n"; };
int a;
private:
int b;
};
Test Test::operator * (const Test t)
{
a = a * t.a;
b = b * t.b;
return *this;
}
Test Test::operator [] (const Test t)
{
std::cout << t.a << "\t" << t.b;
return *this;
}
This works fine like this: testInstance1 = testInstance2 * testInstance3
but, it didnt work under this occasion: testInstance1 = 5 * testInstance3
i have no idea how to overcome this, any suggestions ?