Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operator overloaded

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
hi..
i have some doubts in operator overloading... plz help me out.
I'm having a BaseClass and DerivedClass which is deriving publicly.
Now i'm having overloaded operator methods in class BaseClass which includes ( + , - , * , / , == )
Ive also overloaded the '=' operator which takes a const int as argument!
Now in the application when i try to assign an int to the Derived Object, the compiler gives me an error saying that no overload match is found! ...
but the overloading of '=' works fine when i define it at the DerivedClass level...
Can anyone explain it to me why is it so...
I use aCC compiler under HP-UX..
thanx in advance...
c ya
Shine
 
Try to overload the operator as a friend function (outside your class)
 
Also, you need to declare the operators "virtual" if they are not friend functions. That way, the correct one will be called in DerivedClass when you reference it from a BaseClass pointer.

For more info on this, check out Effective C++ by Scott Meyers. It goes into this in great detail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top