[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3566.0. "Does the "explicit" keyword disappeared ?" by BACHUS::SABLON () Mon May 12 1997 17:01

T.RTitleUserPersonal
Name
DateLines
3566.1explicit has never worked in DEC C++, but will be in 6.0DECC::J_WARDMon May 12 1997 17:3018
"explicit" is a new keyword added into the ANSI C++
draft standard about a year ago. It is not currently nor has
it ever been supported in Digital C++. It will be supported in
V6.0.

BTW, what it means is that the constructor cannot be used
in standard conversions, it can ONLY be used as a constructor.

Anyone who is currently distributed libraries should have a workaround
for compilers that don't currently support non-converting
constructor syntax, i.e:

#ifdef __DECCXX // explicit not supported
#define	explicit	
#else
#define explicit explicit
#endif
3566.2DECC::OUELLETTEmudseason into blackfly seasonMon May 12 1997 17:3742
Perhaps this is a header file problem.
The 'explicit' keyword is reserved by the draft standard.
Since V5.6 implements something less than the draft standard,
but more than the ARM language, there may be something funny happening here.
I see that the current lex.c recognizes "explicit" as a keyword,
that may be new.

From the December 1996 draft...

7.1.2 paragraph 6:

	The explicit specifier shal be used only in declarations of
	constructors within a class declaration; see 12.3.1

12.3.1 paragraph 2:

	An explicit constructor constructs objects just like non-explicit
	constructors, but does so only where the direct-initialization
	syntax (8.5) or where casts (5.2.9, 5.4) are explicitly used.
	A default constructor may be an explicit constructor; such a
	constructor will be used to perform default-initialization (8.5)

... and an example.

An explicit ctor means you must use syntax like:

C c1;
C c2(1);
C c3 = C(1);
C *pc4 = new C(1);
C c5 = (C)1;
C c6 = static_cast<C>(1);

But this syntax is disallowed:

C c7 = 1;

What problem this adition to the language solves and if
V5.6 implements it or even tolerates the keyword in some reasonable
way is unknown to me.  Give me a moment to look...

R.
3566.3DECC::OUELLETTEmudseason into blackfly seasonMon May 12 1997 17:5325
Judy & I collided on our replies.
Here's a little test case I wrote confirming her answer.

cosf> cat explicit.cxx
class C {
  int member;
public:
  explicit C(int);
};

C c1 = 1;

cosf> cxx -c explicit.cxx		!! the 5.6 compiler
cxx: Error: explicit.cxx, line 4: Invalid declaration.
  explicit C(int);
-----------^


cosf> $CEXE/exx_driver -c explicit.cxx	!! the 6.0 compiler
cxx: Error: explicit.cxx, line 7: no suitable constructor exists to convert
from
 "int" to "C"
C c1 = 1;
-------^
1 error detected in the compilation of "explicit.cxx".
3566.4DECCXX::MITCHELLTue May 13 1997 13:153
Just to be clear, V5.5 and V5.6 behave the same
for this case.  The "explicit" keyword will be
supported in V6.0.
3566.5ThanksBACHUS::SABLONTue May 13 1997 13:298