On Jun 18, 2:10 am, Ron Natalie <r...@spamcop.netwrote:
Gaijinco wrote:
Now I tried this and it worked:
cout << int(0);
Is this compiler-dependent or is a language feature?
That is not a call to the int constructor. Int doesn't
have a constructor. It is an explicit conversion to
int. It is (by definition in the language) exactly the
same as:
cout << (int) 0;
That's true, but:
cout << A(0) ;
is also the same as:
cout << (A)0 ;
and
cout << static_cast< A >( 0 ) ;
They're all conversions (according to the standard). The only
real difference is that "type(arg_list)" allows any number of
args (including 0), where as the two other syntaxes only work
with exactly one argument, and that "type(arg_list)" requires
that the type be a single token or a qualified name, where as
the two other syntaxes accept more complicated type names (like
"unsigned long"). But the standard still qualifies all as "type
conversions" (and defines the semantics of A(arg) in terms of
static_cast when there is a single argument).
--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34