PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Re: needed with "discards qualifiers" warning
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: needed with "discards qualifiers" warning

Réponse
 
LinkBack Outils de la discussion
Vieux 28/12/2007, 04h46   #1
Thelma Roslyn Lubkin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: needed with "discards qualifiers" warning

: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
  Réponse avec citation
Vieux 28/12/2007, 11h49   #2
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: needed with "discards qualifiers" warning

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h03.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10280 seconds with 10 queries