views:

123

answers:

1

how can the following declaration be expressed with const first (without typedef)?

double* const (&data)[6]
// ?? const double* (&data)[6] // incorrect, elements, not reference, are const

thank you

+1  A: 

You can't do it.

According to the C++ Standard 8.3.2/1:

Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef (7.1.3) or of a template type argument (14.3), in which case the cv-qualifiers are ignored.

Kirill V. Lyadvinsky
"Cv-qualified references" -- In the question there is a sample line of code and a commented out sample line of different code, neither of which attempts to create a cv-qualified reference. Of course the first line of your answer is correct, but I'm not sure why you followed it with other stuff.
Windows programmer
As I understand from the question he is trying to get const qualified reference.
Kirill V. Lyadvinsky
Oh I see, the other comment inside the commented out line of code. You're right, your quotation from the standard answers that part. Somehow from the question, the valid line of code, and the code in the commented out line of code, I didn't figure out that's what he wanted.
Windows programmer
My bet is that he actually wants the *pointer*, not the reference, to be constant, but that he does not like having the `const` placed in the intermediate position...
David Rodríguez - dribeas