Thread: operator dynamics

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

    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,490
    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,490
    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