|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
:From Erik-wikstrom@telia.com 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>: perator*(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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2007-12-28 05:46, Thelma Roslyn Lubkin wrote:
> :From Erik-wikstrom@telia.com 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>: perator*(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 |
|
![]() |
| Outils de la discussion | |
|
|