Boost logo

Boost Users :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-10-17 10:07:17


"YYW" <yyw1_25_at_[hidden]> wrote

> Arkadiy Vertleyb advised me to insert "const" in "line A". So, the new
> version of "line A" is:
> void operator << (ostream& os, const CMatrix<T>& m)
>
> OK, there's no error.
> But, why?

Because:

>>> static CMatrix<T> eye(int size) { return identity_matrix<T>(size); }

Returns an r-value, and...

>>>
>>> template <class T_>
>>> friend ostream& operator << (ostream& os, CMatrix<T_>& m);
>>> };

you are trying to bind this r-value to a non-const reference. Compiler
correctly refuses to do this.

IOW, compiler tries to prevent you from changing the temporary object since
such changes wouldn't make any sence.

HTH,
Arkadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net