Help needed with "discards qualifiers" warning



 DEVELOP > c-Plus-Plus > Help needed with "discards qualifiers" warning

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Thelma Lubkin"
Date: 27 Dec 2007 02:14:10 PM
Object: Help needed with "discards qualifiers" warning
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>::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.
Can someone help, please?
thanks, --thelma
.

User: "=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?="

Title: Re: Help needed with "discards qualifiers" warning 27 Dec 2007 03:11:27 PM
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>::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.
--
Erik Wikström
.

User: ""

Title: Re: Help needed with "discards qualifiers" warning 28 Dec 2007 03:03:14 AM
On Dec 27, 12:14 pm, Thelma Lubkin <the...@alpha2.csd.uwm.edu> 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>::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.

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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER