472,373 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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 4749
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Steven T. Hatton | last post by:
As far as I know, there is no way to provide a default value for the argument to the constructor A::A(char (&array)) in this example. Correct? struct A{ A(char (&array) ){...
4
by: Rein Anders Apeland | last post by:
Consider the following working code: #include <memory> #include <iostream> void print_ptr( const std::auto_ptr< int > & thePtr = std::auto_ptr< int >() ) {
4
by: Carlos Gomez | last post by:
In VB6 the default for passing variables was ByRef. It was faster and used less memory. Why did MS changed that? Are there any advantages using ByVal over ByRef? (other than ByVal impeding you from...
12
by: huangshan | last post by:
hi all In what condition i need( or mast) a (templates)function return value by reference? can you give me a example thanks
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
16
by: jryden | last post by:
I can do this: struct myInt { int i; }; void func1(myInt &i = myInt()); but not this:
3
by: Gary Wessle | last post by:
I have a method with the last arguments having defaults like this void filing(long, double, const myType& r_mo=NULL, const herType& r_tr=NULL); is that acceptable, if not how is it done?...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
9
by: George2 | last post by:
Hello everyone, I am wondering the default implementation of assignment operator (e.g. when we do not implement assignment operator in user defined class, what will be returned? temporary...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.