This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: invalid cast of an rvalue expression
- From: Ian Lance Taylor <iant at google dot com>
- To: adam99 <adamquestion at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 17 Apr 2009 14:28:25 -0700
- Subject: Re: invalid cast of an rvalue expression
- References: <23105605.post@talk.nabble.com>
adam99 <adamquestion@gmail.com> writes:
> I am getting a following error on g++ 4.1.2
>
>
> SqMatrix.h: In member function 'SqMatrix SqMatrix::operator*(const
> SqMatrix&) const':
> SqMatrix.h:91: error: invalid cast of an rvalue expression of type 'Matrix'
> to type 'const SqMatrix&'
>
>
> for the following code segment
>
> SqMatrix operator * (const SqMatrix &sm) const {
> return (const SqMatrix &) (*(Matrix *)this * sm); }
>
>
> this error did not seem to appear on g++ 3.4.6. Do you know what could be
> the problem?
You are casting an expression to a reference type. That is invalid C++.
Reference types must refer to something stored in a variable or in
memory; they can't refer to expressions.
In this code fragment the cast appears to be completely useless.
Ian