Thread: Operators of abstract classes

  1. #1
    Registered User
    Join Date
    Oct 2007

    Operators of abstract classes

    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

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    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!

    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with abstract classes
    By DavidP in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 03:03 PM
  2. Abstract classes
    By cisokay in forum C++ Programming
    Replies: 17
    Last Post: 05-29-2005, 09:39 AM
  3. Replies: 7
    Last Post: 03-10-2004, 04:10 PM
  4. Abstract classes and operators
    By ygfperson in forum C++ Programming
    Replies: 11
    Last Post: 06-10-2003, 10:50 PM
  5. Purpose of Abstract Classes
    By luckygold6 in forum C++ Programming
    Replies: 15
    Last Post: 04-29-2003, 06:24 PM