Discarded Qualifiers

This is a discussion on Discarded Qualifiers within the C++ Programming forums, part of the General Programming Boards category; Code: BigNum BigNum::operator+(const BigNum& rhs) { if(sign) { if(rhs.GetSign()) { if(this->abs()>rhs.abs()) return Add(this->value, rhs.GetValue(), true); else return Add(rhs.GetValue(), this->value, true); ...

  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136

    Discarded Qualifiers

    Code:
    BigNum BigNum::operator+(const BigNum& rhs)
    {     if(sign)
          {     if(rhs.GetSign())
                {     if(this->abs()>rhs.abs())
                           return Add(this->value, rhs.GetValue(), true);
                      else
                           return Add(rhs.GetValue(), this->value, true);
                }
                else
                {    if(this->abs()>rhs.abs())
                          return Subtract(this->GetValue(), rhs.GetValue(), true);
                     else
                          return Subtract(rhs.GetValue(), this->GetValue(), false);
                }
          }else{
                if(rhs.GetSign())
                {     if(this->abs()>=rhs.abs())
                           return Subtract(this->GetValue(), rhs.GetValue(), false);
                      else
                           return Subtract(rhs.GetValue(), this->GetValue(), true);
                }else{
                      if(this->abs()>rhs.abs())
                           return Add(this->value, rhs.GetValue(), false);
                      else
                           return Add(rhs.GetValue(), this->value, false);
                }
          }
    }
    
    
    
    inline BigNum BigNum::abs()
    {     return BigNum(value);
    }
    Value is a string that contains the value of the bignum, excluding the sign of it which is held by the bool sign. The third parameter of the add and subtract functions is the sign of the result. Also, I have a non-explicit templated constructor that parses through the parameter so that

    Here's the error:

    356 passing `const BigNum' as `this' argument of `class BigNum BigNum::abs()' discards qualifiers

    It is found at every if statement with the abs calls.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    161
    You're calling a non-const method on a constant reference. Try making the abs() method const:

    Code:
    inline BigNum BigNum::abs() const
    {     return BigNum(value);
    }

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Yep, that was it. Another stupid mistake. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. discards qualifiers
    By EstateMatt in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2009, 03:05 PM
  2. Replies: 8
    Last Post: 05-29-2008, 01:47 PM
  3. error: passing [...] discards qualifiers
    By carlorfeo in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2008, 09:45 AM
  4. One error left! Plz help, me=noob
    By rrum in forum C++ Programming
    Replies: 7
    Last Post: 12-01-2005, 01:09 AM
  5. passing discards qualifiers? overloading =...
    By Captain Penguin in forum C++ Programming
    Replies: 9
    Last Post: 10-07-2002, 06:38 PM

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