Help needed with "discards qualifiers" warning

T

Thelma Lubkin

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
 
E

Erik Wikström

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

sonison.james

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top