469,964 Members | 1,678 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Default value for a const reference parameter

Hi folks,
My friend tells that the following function declaration is illegal.

void Foo(const string& strData = "Default");

My friend argues that it is not legal to provide a default value for a
parameter passed by reference or const reference.
But i do not think so.
I looked up in the TCPPPL but nothing of that sort is explicitly
mentioned(or have i missed it ??? ).
Can someone solve the dispute ?

Thanks and Best Regards,
Senthil.

Jul 22 '05 #1
6 4663
On Thu, 9 Sep 2004 16:01:50 +0530, "Senthilvel" <se*****@nospam.com>
wrote:
Hi folks,
My friend tells that the following function declaration is illegal.

void Foo(const string& strData = "Default");

My friend argues that it is not legal to provide a default value for a
parameter passed by reference or const reference.
But i do not think so.
I looked up in the TCPPPL but nothing of that sort is explicitly
mentioned(or have i missed it ??? ).
Can someone solve the dispute ?


The code is fine. You can't do it for a non-const reference, since you
can't bind a non-const reference to a temporary. Basically, the
default parameter can be anything you could pass manually.

Tom
Jul 22 '05 #2
"Senthilvel" <se*****@nospam.com> wrote in message news:<ch**********@news.mch.sbs.de>...
Hi folks,
My friend tells that the following function declaration is illegal. That's correct: what is `string'?
void Foo(const string& strData = "Default");

My friend argues that it is not legal to provide a default value for a
parameter passed by reference or const reference. He's wrong But i do not think so.
I looked up in the TCPPPL but nothing of that sort is explicitly
mentioned(or have i missed it ??? ).
Can someone solve the dispute ?

#include <string>
void Foo(const std::string& strData = "Default");

Thanks and Best Regards,
Senthil.


Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #3
Senthilvel posted:
Hi folks,
My friend tells that the following function declaration is illegal.
void Foo(const string& strData = "Default");

My friend argues that it is not legal to provide a default value for a parameter passed by reference or const reference.
But i do not think so.
I looked up in the TCPPPL but nothing of that sort is explicitly mentioned(or have i missed it ??? ).
Can someone solve the dispute ?

Thanks and Best Regards,
Senthil.


Try
compile
the
bleeding
thing

-Jkop
Jul 22 '05 #4

"JKop" <NU**@NULL.NULL> wrote in message
news:WW******************@news.indigo.ie...
Senthilvel posted:
Hi folks,
My friend tells that the following function declaration

is illegal.

void Foo(const string& strData = "Default");

My friend argues that it is not legal to provide a

default value for a
parameter passed by reference or const reference.
But i do not think so.
I looked up in the TCPPPL but nothing of that sort is

explicitly
mentioned(or have i missed it ??? ).
Can someone solve the dispute ?

Thanks and Best Regards,
Senthil.


Try
compile
the
bleeding
thing

-Jkop


Sometimes, that tells you very little. Especially if you're using a piece
of junk like VC++6.0. The fact that compiler compiles it (which it does - I
tried it) is no indication of its validity as standard-compliant code. :-)

-Howard


Jul 22 '05 #5
Howard posted:

"JKop" <NU**@NULL.NULL> wrote in message
news:WW******************@news.indigo.ie...
Senthilvel posted:
> Hi folks,
> My friend tells that the following function declaration is illegal. >
> void Foo(const string& strData = "Default");
>
> My friend argues that it is not legal to provide a default value for > a parameter passed by reference or const reference.
> But i do not think so.
> I looked up in the TCPPPL but nothing of that sort is explicitly > mentioned(or have i missed it ??? ).
> Can someone solve the dispute ?
>
> Thanks and Best Regards,
> Senthil.
>
>
>
Try
compile
the
bleeding
thing

-Jkop


Sometimes, that tells you very little. Especially if

you're using a piece of junk like VC++6.0. The fact that compiler compiles it (which it does - I tried it) is no indication of its validity as
standard-compliant code. :-)

-Howard


I never commented on whether it was legal code or not.

-JKop
Jul 22 '05 #6
JKop wrote:
Howard posted:

"JKop" <NU**@NULL.NULL> wrote in message
news:WW******************@news.indigo.ie...
Senthilvel posted:

> Hi folks,
> My friend tells that the following function declaration is illegal. >
> void Foo(const string& strData = "Default");
>
> My friend argues that it is not legal to provide a default value for > a parameter passed by reference or const reference.
> But i do not think so.
> I looked up in the TCPPPL but nothing of that sort is explicitly > mentioned(or have i missed it ??? ).
> Can someone solve the dispute ?
>
> Thanks and Best Regards,
> Senthil.
>
>
>

Try
compile
the
bleeding
thing

-Jkop


Sometimes, that tells you very little. Especially if

you're using a
piece of junk like VC++6.0. The fact that compiler

compiles it (which
it does - I tried it) is no indication of its validity as
standard-compliant code. :-)

-Howard


I never commented on whether it was legal code or not.


True, but the OP specifically reports about a dispute as to wether the code
is legal and asks how this dispute is to be resolved.

Best

Kai-Uwe Bux

Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Steven T. Hatton | last post: by
4 posts views Thread by Carlos Gomez | last post: by
12 posts views Thread by huangshan | last post: by
16 posts views Thread by jryden | last post: by
3 posts views Thread by Gary Wessle | last post: by
14 posts views Thread by Abhi | last post: by
9 posts views Thread by George2 | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.