|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello everyone,
I am reading the C++ Programming Language book, but can not find the function of explicit keyword of constructor. Could anyone explain its usage or refer some learning materials please? thanks in advance, George |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
George2 wrote:
> I am reading the C++ Programming Language book, but can not find the > function of explicit keyword of constructor. Could anyone explain its > usage or refer some learning materials please? Have you tried googling? V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
* Victor Bazarov:
> George2 wrote: >> I am reading the C++ Programming Language book, but can not find the >> function of explicit keyword of constructor. Could anyone explain its >> usage or refer some learning materials please? > > Have you tried googling? One problem with googling is that the FAQ confuses explicit constructor calls with placement new syntax. Short of it, "explicit" on a converting constructor suppresses all implicit calls of that constructor, so that all calls must be explicit. This s avoid silly automatic conversions such as the compiler accepting assignment of integer 666 to myVector, treating it as myVector = std::vector<SomeType>(666) -- if you want that, you'll have to write it explicitly, as shown here. Disclaimer: I haven't checked whether that std::vector constructor is "explicit". I assume it is. Cheers, & hth., - Alf -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
In article
<ea06618a-5a8e-419e-8ff2-a1261f2d2169@e23g2000prf.googlegroups.com>, George2 <george4academic@yahoo.com> wrote: > Hello everyone, > > > I am reading the C++ Programming Language book, but can not find the > function of explicit keyword of constructor. Could anyone explain its > usage or refer some learning materials please? > > > thanks in advance, > George The "explicit" keyword is defined in 12.3.1: "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." In other words, implicit conversion of the constructor's parameter is turned off when a constructor is declared explicit. -dr |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Mon, 10 Dec 2007 22:00:36 -0800 (PST) in comp.lang.c++, George2
<george4academic@yahoo.com> wrote, >I am reading the C++ Programming Language book, but can not find the >function of explicit keyword of constructor. Section 11.7.1 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
George2 wrote:
> Hello everyone, > > > I am reading the C++ Programming Language book, but can not find the > function of explicit keyword of constructor. Have you tried the index? -- Ian Collins. |
|
![]() |
| Outils de la discussion | |
|
|