473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 4838
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.