This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [G++] compilation error: difference between int and bool


noon@cote-dazur.com (Fabrice Bauzac) writes:

> Could anyone explain me why
> 
> ==============================
> #include <vector>
> 
> class T {
>   vector <bool> v;
>   bool &element (int i) { return v[i]; }
> };
> ==============================
> 
> doesn't compile?

I'm not a C++ guru, but I think you cannot return a non-const
reference to a temporary object (and a temporary object is required
because bool and int are different types).

-- 
Florian Weimer 	                  Florian.Weimer@RUS.Uni-Stuttgart.DE
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]