Topic: point of defn and default and default arguments
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/08/09 Raw View
In article <DCxJ3u.A96@online.tmx.com.au> tony@online.tmx.com.au (Tony
Cook) writes:
|> Is the following legal:
It's legal.
|> class T
|> {
|> public:
|> T() {}
|> //
|> T(int,
|> T const &def_ = T() // note this - use before end of class
|> ) { }
|> };
|> int main()
|> {
|> T t(0);
|> return 0;
|> }
|> Why it might be legal:
|> default arguments are evaluated at the point of use.
|> [dcl.fct.default]
|> 9 Default arguments are evaluated at each point of call before entry
|> into a function.
Correct.
|> Why it might not be legal:
|> names for default arguments are bound at point of declaration,
|> and T is not fully defined where the default argument is declared.
|> [dcl.fct.default]
|> 5 Default argument expressions have their names bound and their types
|> checked at the point of declaration.
|> [class] p2
|> A
|> class is considered defined after the closing brace of its class-
|> specifier has been seen even though its member functions are in gen-
|> eral not yet defined.
Binding a name does not require a complete type. In fact,
technically, it doesn't require any semantic information concerning
the name. (In practice, there is no way for you to make a name known
to the compiler without providing some semantic information.)
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: tony@online.tmx.com.au (Tony Cook)
Date: 1995/08/07 Raw View
Is the following legal:
class T
{
public:
T() {}
//
T(int,
T const &def_ = T() // note this - use before end of class
) { }
};
int main()
{
T t(0);
return 0;
}
Why it might be legal:
default arguments are evaluated at the point of use.
[dcl.fct.default]
9 Default arguments are evaluated at each point of call before entry
into a function.
Why it might not be legal:
names for default arguments are bound at point of declaration,
and T is not fully defined where the default argument is declared.
[dcl.fct.default]
5 Default argument expressions have their names bound and their types
checked at the point of declaration.
[class] p2
A
class is considered defined after the closing brace of its class-
specifier has been seen even though its member functions are in gen-
eral not yet defined.
--
Tony Cook - tony@online.tmx.com.au
100237.3425@compuserve.com