Re: arrays, pointers, and constness

From: Kevin B. McCarty <kmccarty_at_gmail.com>
Date: Fri, 9 Nov 2007 09:49:17 -0800


On Nov 9, 2007 8:04 AM, Axel Naumann <Axel.Naumann_at_cern.ch> wrote:
> Hi Annalisa,
>
>
> Annalisa De Caro wrote:

> > When I made the following:
> > .L proviamo.C++
> > the compilation stops with the following message:
> > ./proviamo.C:31: error: cannot convert `const Float_t (*)[3]' to `Float_t*' in initialization
>
> You have an array of "const Float_t"s, and you try to set ccc (a pointer
> to a Float_t) by making it point to the array. That won't work; ccc
> doesn't respect the const-ness of the array values: the array has const
> Float_t, ccc doesn't. Make it "const Float_t *ccc" instead.

I didn't notice the const-ness of the initial array; of course Axel is correct to point this out. So in your second example, you really should have

const Float_t * ccc = fgkAl3parameters;

(again, omitting the & operator).

best regards,

-- 
Kevin B. McCarty <kmccarty_at_princeton.edu>   Physics Department
WWW: http://www.princeton.edu/~kmccarty/    Princeton University
GPG: public key ID 4F83C751                 Princeton, NJ 08544
Received on Fri Nov 09 2007 - 18:49:44 CET

This archive was generated by hypermail 2.2.0 : Fri Nov 09 2007 - 23:50:01 CET