Re: Help needed with "discards qualifiers" warning



 DEVELOP > c-Plus-Plus > Re: Help needed with "discards qualifiers" warning

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Thelma Roslyn Lubkin"
Date: 27 Dec 2007 10:46:34 PM
Object: Re: Help needed with "discards qualifiers" warning
:From
Thu Dec 27 15:20:33 2007
:On 2007-12-27 21:14, Thelma Lubkin wrote:
:> matrixd.cc:244: warning: passing `const Octonion<double>' as `this'
:> argument of
:> `Octonion<scalar> Octonion<scalar>::operator*(const
:> Octonion<scalar>&) [with
:> scalar = double]' discards qualifiers
:>
:> I seem to get valid results if I ignore the warning, but I'd like to
:> understand what it means and to modify my classes so that it no longer
:> occurs.
:I am not quite sure (so I ought to not say anything) but have you
:declared the * operator as const? E.g.:
:template<class scalar>
:class Octonion : public Vector
:{
: // ...
: Octonion<scalar> operator*(const> Octonion<scalar>&) const;
: // ...
:};
:Your code would probably not compiler if you had not, but who knows.
I have the const on the argument, but not on the operator. It
does, however both compile and run.
--thelma
--
:Erik Wikström
.

User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?="

Title: Re: Help needed with "discards qualifiers" warning 28 Dec 2007 05:49:00 AM
On 2007-12-28 05:46, Thelma Roslyn Lubkin wrote:

:From

Thu Dec 27 15:20:33 2007
:On 2007-12-27 21:14, Thelma Lubkin wrote:
:> matrixd.cc:244: warning: passing `const Octonion<double>' as `this'
:> argument of
:> `Octonion<scalar> Octonion<scalar>::operator*(const
:> Octonion<scalar>&) [with
:> scalar = double]' discards qualifiers
:>
:> I seem to get valid results if I ignore the warning, but I'd like to
:> understand what it means and to modify my classes so that it no longer
:> occurs.

:I am not quite sure (so I ought to not say anything) but have you
:declared the * operator as const? E.g.:

:template<class scalar>
:class Octonion : public Vector
:{
: // ...
: Octonion<scalar> operator*(const> Octonion<scalar>&) const;
: // ...
:};

:Your code would probably not compiler if you had not, but who knows.

I have the const on the argument, but not on the operator. It
does, however both compile and run.

If we simplify the problematic code as much as possible, does it look
like this:
const Octonion<double> a;
Octonion b;
a * b;
i.e. you have a const Octonion which you try to multiply with a
(possibly) non-const Octonion. If that is the case you must make the
operator const too.
--
Erik Wikström
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER