🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Tony Cook Mon, 07 Aug 1995 07:21
point of defn and default and default arguments
#1665
Author: Tony Cook
Date: Mon, 07 Aug 1995 07:21
42 lines
1366 bytes
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
Re: point of defn and default and default arguments
#1685
Author: James Kanze US/ESC 60/3/141 #407...
Date: Wed, 09 Aug 1995 08:48
56 lines
2188 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads