🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3383

Re: Explicit? What's that?

#3383
From: Steve Clamage
Date: Tue, 20 Feb 1996 18:39
40 lines
2064 bytes
In article 2ne@charnel.ecst.csuchico.edu, mcelroy@ecst.CSUChico.EDU (James Robert McElroy) writes:
>Borland sent me an upgrade offer for C++ V. 5.0.  Among
>the new features they say they support is "Explicit".
>No mention of what "Explicit" means is given.
>
>What is this critter?

A new language feature that lets you specify that a constructor is not
to be used for implicit type conversions. It has a meaning only for
constructors that can take a single argument. Example:

	class String {
	public:
		String();
		String(const char*);
		explicit String(int); // establish minimum size
	};
	String operator+(const String&, const String&);

	String s("Hello");
	String t = s + " World"; // OK, implicitly converts char* to String
	t = s + 2; // ERROR
	t = s + String(2); // OK, convert int to String explicitly

Without the "explicit", the expression s+2 would silently create a String
of capacity 2 and append it to s. Probably that isn't what the programmer
had in mind. With "explicit", the implicit conversion doesn't occur.

The last line is OK because the constructor is invoked explicitly.

---
Steve Clamage, stephen.clamage@eng.sun.com


[ To submit articles: Try just posting with your newsreader.
		      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID: <4gd4b9$c43@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <4gb00j$2ne@charnel.ecst.csuchico.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Explicit?  What's that?
Date: 20 Feb 1996 18:39:42 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4gd4b9$c43@engnews1.Eng.Sun.COM>
References: <4gb00j$2ne@charnel.ecst.csuchico.edu>
Reply-To: clamage@Eng.sun.com
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 1149
X-Lines: 34
Originator: clamage@taumet