Question about explicit template instantiation
Edward Diener
eddielee_no_spam_here at tropicsoft.com
Mon Feb 11 14:53:59 PST 2008
Janice Caron wrote:
> On 10/02/2008, Edward Diener <eddielee_no_spam_here at tropicsoft.com> wrote:
>> I still do not understand what the object used for the instantiation is.
>> In your example above what is:
>>
>> A!(int)
>>
>> ? Is it some kind of namespace ?
>
> Yes. It is exactly a namespace.
>
>
>
>> Can I say:
>>
>> A!(int) x;
>>
>> ?
>
> Sometimes, but only in special case. If you don't specify a member of
> the namespace, then the compiler will /assume/ a member whose name is
> the same as that of the template. So, if we have:
>
> template A(T)
> {
> int A;
> }
>
> then
>
> A!(int) x;
>
> would be shorthand for
>
> A!(int).A x;
>
> But if there wasn't an A in the namespace, then it wouldn't compile.
> That little "trick" is really, really useful, because it can make for
> a lot less typing. So - in general - A!(T) with no member, is the same
> thing as A!(T).A, if A!(T).A exists.
>
> /What/ is it, depends. It's whatever A!(T).A is.
Thanks for the explanation !
More information about the Digitalmars-d
mailing list