Question about explicit template instantiation
Janice Caron
caron800 at googlemail.com
Sun Feb 10 15:23:32 PST 2008
On 10/02/2008, Jesse Phillips <jessekphillips at gmail.com> wrote:
> Well, you can't write A!(int) x; unless you precede it with alias.
Not so.
template A(T)
{
int A;
}
A!(double) = 42;
writefln(A!(double)); // prints 42
writefln(typeof(A!(double))); // prints double
In this example, A!(double) is short for A!(double).A, which in an
int, so we can assign a value to it and print it.
But
template A(T)
{
struct A
{
int x;
}
}
In /this/ example A!(T).A is a type. (And hence, so is A!(T)). Observe
that there's a neater way of writing that though. We can abbreviate
that to
struct A(T)
{
int x;
}
More information about the Digitalmars-d
mailing list