0

In the following code, is there a way to make extint *smaller point to both variables of extint type and const extint type?

extint extint::operator+ (const extint &b)
{
    extint result;
    int sum;
    extint* smaller = (num.size() < b.num.size()) ? this : &b;

    //do stuff

    return result;
}

Please advise.

dmbhatti
  • 314
  • 2
  • 11

1 Answers1

0

The common type is const extint*, so you may do

const extint* smaller = (num.size() < b.num.size()) ? this : &b;

(but then you can't modify smaller, even for this).

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Im a new programmer so I may be doing something totally nooby here. I have no idea. Basically I overloaded the operator as part of a class that defines an integer that can take any size. In this function basically I intend to add two of the integers that can take any size. I checked out this syntax online. I only need to pass one of the integers. in the online example it was being passed as a constant. i thought doing that was important. Also will const extint* take an int? thanks for the help! – dmbhatti Aug 23 '15 at 16:29
  • kindly explain the concept of common type. how is const extint more "common" than simply extint? – dmbhatti Aug 23 '15 at 16:57
  • @dmbhatti: you can do `const extint* const_ptr = no_const_ptr;` but not `extint* no_const_ptr = const_ptr;`. That why `const extint*` is *more common* than `extint*`. – Jarod42 Aug 24 '15 at 13:22