Help needed with "discards qualifiers" warning

Discussion in 'C++' started by Thelma Lubkin, Dec 27, 2007.

  1. I use my own matrix and vector classes. I wrote them before such
    things were generally available and I've stuck with them ever since.
    I've just added an Octonion class derived from the vectors class and
    I'm trying to do some matrix arithmetic where the elements of the
    matrices are Octonions. (My Octonions are essentially 8-component
    vectors with a multiplication table that I compute at runtime. Like
    vectors, they are a template class, but I've yet to assign anything
    but double as the template scalar)
    Things have been working pretty well, but now
    I've gotten this warning when trying to multiply a matrix by an
    Octonion:

    matrixd.cc:244: warning: passing `const Octonion<double>' as `this'
    argument of
    `Octonion<scalar> Octonion<scalar>::eek: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.

    Can someone help, please?

    thanks, --thelma
    Thelma Lubkin, Dec 27, 2007
    #1
    1. Advertising

  2. On 2007-12-27 21:14, Thelma Lubkin wrote:
    > I use my own matrix and vector classes. I wrote them before such
    > things were generally available and I've stuck with them ever since.
    > I've just added an Octonion class derived from the vectors class and
    > I'm trying to do some matrix arithmetic where the elements of the
    > matrices are Octonions. (My Octonions are essentially 8-component
    > vectors with a multiplication table that I compute at runtime. Like
    > vectors, they are a template class, but I've yet to assign anything
    > but double as the template scalar)
    > Things have been working pretty well, but now
    > I've gotten this warning when trying to multiply a matrix by an
    > Octonion:
    >
    > matrixd.cc:244: warning: passing `const Octonion<double>' as `this'
    > argument of
    > `Octonion<scalar> Octonion<scalar>::eek: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.

    --
    Erik Wikström
    Erik Wikström, Dec 27, 2007
    #2
    1. Advertising

  3. Thelma Lubkin

    Guest

    On Dec 27, 12:14 pm, Thelma Lubkin <> wrote:
    > I use my own matrix and vector classes. I wrote them before such
    > things were generally available and I've stuck with them ever since.
    > I've just added an Octonion class derived from the vectors class and
    > I'm trying to do some matrix arithmetic where the elements of the
    > matrices are Octonions. (My Octonions are essentially 8-component
    > vectors with a multiplication table that I compute at runtime. Like
    > vectors, they are a template class, but I've yet to assign anything
    > but double as the template scalar)
    > Things have been working pretty well, but now
    > I've gotten this warning when trying to multiply a matrix by an
    > Octonion:
    >
    > matrixd.cc:244: warning: passing `const Octonion<double>' as `this'
    > argument of
    > `Octonion<scalar> Octonion<scalar>::eek: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.
    >
    > Can someone help, please?
    >
    > thanks, --thelma


    Could you please write what's on matrixd.cc:244 that's causing this
    warning. Since error and warning messages are compiler and setting
    dependent it's hard to make out the cause from these messages.

    But by the look of it, it seems that your LHS operand is a const
    object and your operator*() is not a const member.

    Thanks and regards
    Sonison James
    , Dec 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. danny van elsen
    Replies:
    6
    Views:
    41,230
    Pete Becker
    Apr 24, 2005
  2. Jason
    Replies:
    6
    Views:
    8,990
    Mike Wahler
    Oct 9, 2003
  3. Thelma Roslyn Lubkin
    Replies:
    1
    Views:
    348
    Erik Wikström
    Dec 28, 2007
  4. Andre
    Replies:
    4
    Views:
    24,814
    Andrey Tarasevich
    Mar 4, 2008
  5. Greg Hauptmann
    Replies:
    0
    Views:
    290
    Greg Hauptmann
    Feb 6, 2009
Loading...

Share This Page