operator dynamics

This is a discussion on operator dynamics within the C++ Programming forums, part of the General Programming Boards category; Code: Base& Base::operator+=(Base& e) { } Base& Base::operator+=(Derived& e) { } int main() { Base *x, z; Derived y; z ...

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493

    operator dynamics

    Code:
    Base& Base::operator+=(Base& e) {
    
    }
    Base& Base::operator+=(Derived& e) {
    
    }
    int main() {
      Base *x, z;
      Derived y;
      z += y;
    
    }
    My problem is that the operator+=(Base&) is called instead of the other one. Any suggestions?
    Last edited by ygfperson; 05-03-2003 at 03:56 PM.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    it's doing what its supposed to?

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Originally posted by Jamsan
    it's doing what its supposed to?
    Sorry, typo. It's going to Base&, but i want it to accept Derived&. I've edited the question accordingly.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    try casting it perhaps ?

  5. #5
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    No luck.

    BTW, my example isn't technically accurate... I dereferenced a Base pointer to a Derived object, but the rest is the same.

    Casting doesn't work because it's already Derived&. I tried dynamic_cast<Derived&>() but no luck either.

Popular pages Recent additions subscribe to a feed

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