Can anyone please tell me how to define the operator functions for abstract classes..
For example, there are two sub classes of a base abstract class.. So how to define the operator functions for them
Can anyone please tell me how to define the operator functions for abstract classes..
For example, there are two sub classes of a base abstract class.. So how to define the operator functions for them
If the operators don't need to know about the concrete type, it's easy. Just define them in the base as any others.
If they're unary, you can make them virtual, though I would suggest you make the actual operator non-virtual in the base and call a virtual normal function from there. I don't know, it just seems like a better way to do it.
If they're binary, you've got a binary dispatch case and then you're in real trouble.
The thing is ... operator overloading is something typically done for value-like classes, whereas polymorphism is done for "identity-heavy" classes. The use cases where you'd need both should be very rare.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law