Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6798
| From | yatremblay@bel1lin202.(none) (Yannick Tremblay) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Use of const for non-reference parameters |
| Date | 2011-06-16 11:50 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <itcqmr$s6o$1@dont-email.me> (permalink) |
| References | <ygfhb7qi2dg.fsf@janus.isnogud.escape.de> <95tvubFd2pU10@mid.individual.net> |
In article <95tvubFd2pU10@mid.individual.net>,
Ian Collins <ian-news@hotmail.com> wrote:
>On 06/16/11 08:53 PM, Urs Thuermann wrote:
>> I'm working on a project that uses const for function parameters that
>> are neither references nor pointers, i.e. something like this:
>>
>> int foo(const int a) { ... }
>> int bar(const string b) { ... }
>>
>> I don't see why this is useful. Since the argument is copied to the
>> called function it doesn't matter to the caller whether the argument
>> is modified or not. So why would one want to write code like that?
>
>It doesn't make a lot of sense. Maybe they forgot the &?
>
It is not needed in the interface definition (albeit not harmful per
se) but in implementation:
int foo(const int a)
{
//... use a without modifying it
}
is comparable to:
int foo()
{
const int a = getAFromSomewhere();
// ... use a without modifying it
}
The const, albeit less important than a const& parameter that
documents the interface can still be useful.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Use of const for non-reference parameters Urs Thuermann <urs@isnogud.escape.de> - 2011-06-16 10:53 +0200
Re: Use of const for non-reference parameters Ian Collins <ian-news@hotmail.com> - 2011-06-16 21:15 +1200
Re: Use of const for non-reference parameters yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-06-16 11:50 +0000
Re: Use of const for non-reference parameters "Balog Pal" <pasa@lib.hu> - 2011-06-16 11:35 +0200
Re: Use of const for non-reference parameters Urs Thuermann <urs@isnogud.escape.de> - 2011-06-16 15:21 +0200
Re: Use of const for non-reference parameters Marc <marc.glisse@gmail.com> - 2011-06-16 16:25 +0000
Re: Use of const for non-reference parameters Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-16 02:38 -0700
Re: Use of const for non-reference parameters Saeed Amrollahi <amrollahi.saeed@gmail.com> - 2011-06-16 03:15 -0700
Re: Use of const for non-reference parameters "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-06-16 13:33 +0200
Re: Use of const for non-reference parameters Howard Hinnant <howard.hinnant@gmail.com> - 2011-06-16 09:50 -0700
Re: Use of const for non-reference parameters Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-16 13:22 -0700
Re: Use of const for non-reference parameters Howard Hinnant <howard.hinnant@gmail.com> - 2011-06-16 13:49 -0700
Re: Use of const for non-reference parameters Gerhard Fiedler <gelists@gmail.com> - 2011-06-17 11:41 -0300
Re: Use of const for non-reference parameters "Balog Pal" <pasa@lib.hu> - 2011-06-17 18:40 +0200
Re: Use of const for non-reference parameters "Thomas J. Gritzan" <phygon_antispam@gmx.de> - 2011-06-17 22:01 +0200
Re: Use of const for non-reference parameters "Balog Pal" <pasa@lib.hu> - 2011-06-18 03:01 +0200
Re: Use of const for non-reference parameters Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-17 13:30 -0700
Re: Use of const for non-reference parameters Howard Hinnant <howard.hinnant@gmail.com> - 2011-06-17 16:51 -0700
Re: Use of const for non-reference parameters "Johannes Schaub (litb)" <schaub.johannes@googlemail.com> - 2011-06-17 16:35 +0200
Re: Use of const for non-reference parameters Juha Nieminen <nospam@thanks.invalid> - 2011-06-18 10:14 +0000
Re: Use of const for non-reference parameters Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-06-18 11:45 +0000
Re: Use of const for non-reference parameters "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-18 19:27 +0200
csiph-web