From -5140387494031054424
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,e5334c2e3a820d75,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,e5334c2e3a820d75,start
X-Google-Attributes: gidf78e5,public
From: "Ivo" <ivo.penzar@infolink-software.com>
Subject: Q: Const Reference as Default Parameter
Date: 2000/05/24
Message-ID: <8gbfo7$3r9$1@as102.tel.hr>#1/1
X-Deja-AN: 626352704
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Priority: 3
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=US-ASCII
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 959100365 mail2news:20393 mail2news mail2news.demon.co.uk
Organization: HiNet
X-MSMail-Priority: Normal
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Mime-Version: 1.0
NNTP-Posting-Date: 22 May 2000 14:20:55 GMT
Newsgroups: comp.lang.c++,comp.std.c++

Suppose I have a class C and a function

void f(const C&);

Now, I want to provide a default argument for this function,
something like

void f(const C& c=C());

(provided that class C defines a meaningful public default constructor).

Unfortunately, this construct is not aligned with the latest C++ standard.
Indeed, MSVC++ (debug mode only) would report a warning, while GNU C++
compilers would report an error.

To apply a fixture, I can declare something like

void f(const C& c=(C&)(const C&)C());

Otherwise, I can overload my function f

void f(const C&);
void f() {C c; f(c);};

In the case I need it frequently, for different classes and their various
constructors (with or without parameters), I can (reluctantly) use a
macro definition:

TEMP_OBJ_INST(T) (T&)(const T&)T
void f(const C& c=TEMP_OBJ_INST(C)());
void g(const D& d=TEMP_OBJ_INST(D)(-1, 3.14));

- where D was another class with public constructor D(int, double).

Is there any other, more elegant way to put it right?

Thanks,
Ivo


---
[ 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_mti/std-c++/faq.html              ]




