From 3117827388166284601
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6a0e273cd04a6fa1,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-01-09 09:24:47 PST
Path: archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!194.159.255.21.MISMATCH!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Sektor van Skijlen" <sektor@spam-buffer.aldec.com>
Newsgroups: comp.std.c++
Subject: new meaning of explicit keyword
Date: Wed,  9 Jan 2002 16:59:16 GMT
Organization: tp.internet - http://www.tpi.pl/
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <a1hsph$p4k$1@news.tpi.pl>
X-Trace: mail2news.demon.co.uk 1010595562 mail2news:19406 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
NNTP-Posting-Date: Wed, 9 Jan 2002 16:57:21 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Lines: 44
Xref: archiver1.google.com comp.std.c++:8919

For now, the "explicit" keyword allows a type CONSTRUCTOR to
disallow implicit conversions into this type. This keyword could be
also used to signify, that this implicit conversion is not allowed for
the object initialization. For example:

int x = 'c'; // allowed
explicit int x = 'c'; // not allowed!
explicit int x = int( 'c' ); // allowed

This feature could be mostly used in a situation, where the implicit
conversion, granted by standard, is a disadvantage in some cases.
For example, one of std::string's constructors take two arguments,
which mean an amount of characters and a character. The
disadvantage is that the compiler won't see any error if you pass
arguments in wrong order. This will be passed, because there
will be ALLOWED conversion from char to size_t and in reverse.
This bug is always hard to detect.

Using this feature you can state:

string( size_t size, explicit char ch );

And then this:

string s( 'c', 12 );

won't compile, because "12" can't be implicitly converted to char.
However it can be worked around:

string s( 'c', char( 12 ) );


Regards,
--
((
 )) ektor


---
[ 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://www.research.att.com/~austern/csc/faq.html                ]



