From 6096061852694443725
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fe6310a7fb6a4c8c
X-Google-Attributes: gidf78e5,public
From: "Bradd W. Szonye" <bradds@concentric.net>
Subject: Re: const int& or int const&
Date: 1998/02/06
Message-ID: <6batt7$dph@examiner.concentric.net>#1/1
X-Deja-AN: 322700229
References: <34D8AD3C.5C38416B@heidelbg.ibm.com>
X-Original-Date: Wed, 4 Feb 1998 18:31:23 -0500
Content-Type: text/plain; charset="iso-8859-1"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Concentric Internet Services
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNNtat0y4NqrwXLNJAQFv4gH9FnAcC9djtRgO3KGFSwb3S1UkFp8tfztO qFx7hBZapGXPvhFNJ8BpdQV8XeFU2typFTJZHRHPArQi7MMcwQIiGw== =RyAM
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


Martin Neimeier wrote in message <34D8AD3C.5C38416B@heidelbg.ibm.com>...
>What is the difference between the three method-headers ?
>
>void foo(const in& foo_var);
>void foo(int const& foo_var);

These two are the same, and mean "reference to constant integer."

>void foo(const int const& foo_var);

This is ill-formed as written; redundant cv-qualifiers are not allowed
except as the by-product of a typedef or template instantiation. (The
cv-qualifiers, in case you are unfamiliar, are "const" and "volatile."
They are redundant in this example because both consts modify "int.")

The rule of thumb is that "const" modifies the syntactic element
immediately to its left. The major exception is that "const" written
left of the declared type modifies the element to its right (the type):

    brackets indicate const grouping
    [const int] *
    [int const] *
    [int const int] * // illegal
    [int const] [* const]

By the way, I prefer the "T const &" syntax myself; it works better with
text processing tools and is easier to explain than the full rule, which
has an exception.

Is this a FAQ? It seems to be a common question recently. I know I've
seen it in exactly this form before.

Bradd W. Szonye
bradds@concentric.net
http://www.concentric.net/~Bradds
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern/std-c++/faq.html                  ]



