From -6687436931287000313
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fe6310a7fb6a4c8c
X-Google-Attributes: gidf78e5,public
From: "Tom McKearney" <no@spam.com>
Subject: Re: const int& or int const&
Date: 1998/02/06
Message-ID: <6bb9ek$1hb$1@ha2.rdc1.md.home.com>#1/1
X-Deja-AN: 322700230
References: <34D8AD3C.5C38416B@heidelbg.ibm.com>
X-Original-Date: Wed, 4 Feb 1998 21:57:58 -0500
X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: My House
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNNtaxUy4NqrwXLNJAQH32gIApPVBQ32oaSjGOt8A7pvKIbzHLbioScNB VSAqVi452KxXbuFmsuJXB9cV3wurcEM4H+jDnOQw9aFQrKKHAAtR+Q== =ofsM
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);
>void foo(const int const& foo_var);

You can get this from the C++ FAQ, but here goes (hope I am thinking
clearly)...

1) void foo(const int& foo_var);

this is a function that takes a reference to a const int.  This means the
integer can't be modified.

2) void foo(int const& foo_var);

this is also a function that takes a reference to a const int.  This means
the integer can't be modified.

3) void foo(const int const& foo_var);

I am not sure if this is valid.  I am too lazy to look it up, but I think it
is invalid.

The difference between placement of const is easier to define with
pointers..

1) void foo(const int* foo_var)
2) void foo(int const* foo_var)

These would take a pointer to a const int.  The integer is not modifiable,
but the pointer can be modified (i.e. reseated).

3) void foo(int *const foo_var)

This takes a const pointer to an integer.  The integer can be modified, but
the pointer can be.

4) void foo(const int* const foo_var)

This takes a const pointer to a const integer.  Neither the integer, nor the
pointer may be modified.

I hope this helps.

Tom McKearney
---
[ 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                  ]



