hi all~
i built a class which supports operator overloading, here is my code:
This works fine like this: testInstance1 = testInstance2 * testInstance3Code: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; }
but, it didnt work under this occasion: testInstance1 = 5 * testInstance3
i have no idea how to overcome this, any suggestions ?