| 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
.
|
|
|
|

|
Related Articles |
|
|