Operator overloading and inheritence

This is a discussion on Operator overloading and inheritence within the C++ Programming forums, part of the General Programming Boards category; Hi, ive been working on a operator = overloading function, and wondered whether it worked when in an inheritence hierarchy. ...

  1. #1
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92

    Operator overloading and inheritence

    Hi,

    ive been working on a operator = overloading function, and wondered whether it worked when in an inheritence hierarchy.

    For example my base class implements the operator =, and the derived classes inherit this?

    Do the derived classes inherit this? Does polymorphism allow this operator = class type to be derived at run time?

    For example if i have a the following code:

    Code:
    Juxtacrine j = new Juxtacrine(); // derived object from Cell
    Morphogen m = new Morphogen(); //derived object from Cell different to Juxtacrine
    
    m = j; // calls Cell& operator =(Cell& c) - base class implementation
    Now at the moment it doesnt seem to work as each time i call the =operator it makes a copy of type const Cell&.

    Am i going down the right path ? or do i need to rethink what im doing?

    Thanks in advance..

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    It doesn't get inherited. You would need to create an assignment operator for your derived class which calls the assignment operator of the base class and then does any special things for the derived class.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92
    ok cool thanks, how do i call the baseclass assignment operator?

  4. #4
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92
    dont worry got it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pipes, inheritence and some newbie questions
    By grasshopa in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2006, 06:00 AM
  2. Pipes, inheritence, newbie questions
    By grasshopa in forum Windows Programming
    Replies: 0
    Last Post: 02-28-2006, 05:17 AM
  3. do i understand inheritence properly
    By Anddos in forum C++ Programming
    Replies: 8
    Last Post: 11-16-2005, 03:36 PM
  4. class inheritence with constructor parameters
    By drdodirty2002 in forum C++ Programming
    Replies: 3
    Last Post: 06-20-2005, 06:49 PM
  5. Multiple Inheritence
    By face_master in forum C++ Programming
    Replies: 14
    Last Post: 12-11-2002, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21