link error for 2+ static this()

Derek Parnell derek at psych.ward
Wed Jun 7 07:17:37 PDT 2006


On Wed, 07 Jun 2006 22:34:27 +1000, Johan Granberg  
<lijat.meREM at OVEgmail.com> wrote:

> Carlos Santander wrote:
>> Walter Bright escribió:
>>> BCS wrote:
>>>> this gives a link error with somthing about duplicate symbols.
>>>>
>>>> <code>
>>>> void main(){}
>>>> static this(){}
>>>> static this(){}
>>>> <\code>
>>>
>>> That's because there are two static constructors, which is not legal.
>>  But it could be caught at compile time, instead, giving an appropriate  
>> error message.
>>
>
> quote from the spec
> "Order of Static Construction within a Module
>
> Within a module, the static construction occurs in the lexical order in  
> which they appear."
>
> doesn't this imply that multiple static constructors are legal?

It doesn't for me. I thought that meant that if one has more than one  
static constructor in a module then they run in lexical order. For example  
...

   module test;
   class Foo
   {
     static this() { ... }
   }
   class Bar
   {
     static this() { ... }
   }

   static this() { . . .}

In this case, Foo's ctor runs first, then Bar's and finally the module's.

The spec does not mean that one can have multiple class ctors per class or  
module ctors per module.
-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d-bugs mailing list