PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > explicit keyword
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
explicit keyword

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 06h00   #1
George2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut explicit keyword

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
  Réponse avec citation
Vieux 11/12/2007, 06h01   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: explicit keyword

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


  Réponse avec citation
Vieux 11/12/2007, 06h13   #3
Alf P. Steinbach
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: explicit keyword

* 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?
  Réponse avec citation
Vieux 11/12/2007, 06h34   #4
Dave Rahardja
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: explicit keyword

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
  Réponse avec citation
Vieux 11/12/2007, 07h34   #5
David Harmon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: explicit keyword

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
  Réponse avec citation
Vieux 11/12/2007, 07h42   #6
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: explicit keyword

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h06.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12809 seconds with 14 queries