| Thread overview | |||||
|---|---|---|---|---|---|
|
March 23, 2008 Question about template instantiation scope | ||||
|---|---|---|---|---|
| ||||
In the section about template instantiation scope, the below example is given of illegality:
"module a
template TFoo(T) { void bar() { func(); } }
module b
import a;
void func() { }
alias TFoo!(int) f; // error: func not defined in module a"
From this I assume that a template which refers to some type or object which is not in the module of the template declaration must import the module where the type or object is defined in order to be instantiated at all. For example:
"module c
void func() { }
module a
import c;
template TFoo(T) { void bar() { func(); } }
module b
import a;
void func() { }
alias TFoo!(int) f; // legal"
Is this correct ?
| ||||
March 23, 2008 Re: Question about template instantiation scope | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Reply to Edward,
> From this I assume that a template which refers to some type or
> object which is not in the module of the template declaration must
> import the module where the type or object is defined in order to be
> instantiated at all.
>
> Is this correct ?
>
Yes.
The use of template mixin allows the reverse behavior. But that's for later
| |||
March 23, 2008 Re: Question about template instantiation scope | ||||
|---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Reply to Edward,
>
>> From this I assume that a template which refers to some type or
>> object which is not in the module of the template declaration must
>> import the module where the type or object is defined in order to be
>> instantiated at all.
>>
>> Is this correct ?
>>
>
> Yes.
>
> The use of template mixin allows the reverse behavior. But that's for later
>
>
Thanks ! As you say, I will look at mixins once I understand D templates thoroughly, but not beforehand.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply