Question about explicit template instantiation

Tyro[a.c.edwards] no at spam.com
Sun Feb 10 13:37:32 PST 2008


Edward Diener さんは書きました:
> Tyro[a.c.edwards] wrote:
>> Edward Diener さんは書きました:

[snip]
> 
> I understand what a template is and that the instantiation of a template 
> is a type ( class ). So in the example above 'a' and 'b' are aliases for 
> types, ie. typedef in C++. Therefore the statements "a.f = 3;" and 
> 'assert(b.f == 3);" made no sense to me.

Actually, I said a "template is NOT a type." However, I don't tink I 
have enought experience in either English or D to explain thing to you 
so I'll stop before embarrasing myself further.

> But I think I understand them now, but hopefully someone will clarify 
> things for me. It seems in D one can instantiate a temporary object from 
> a type which has a default constructor simply by using the type, whereas 
> in C++ one must use the type followed by '()'. So whereas if X were a 
> class with a default constructor with the data member Y, in C++ one 
> would use 'X().Y' to access the temporary's Y data member while in D it 
> appears one can use 'X.Y' to access the temporary's data member.

Unfortunately I don't think you undersand... see previous comment.

> What I quoted in my OP was all directly from the documentation, not 
> anything I made up. Somehow you think that the lines:
> 
> a.f = 3;
> assert(b.f == 3); // a and b refer to the same instance of TFoo
> 
> were inserted by me. No ! They were in the doc and they appeared to be 
> incorrect, and I wanted an explanation for them.

No, actually I went to the document that you were reading, read a little 
further down the page and took an example of a CLASS template and used 
it to attempt an explanation. Hopefully, someone will be able to assist you.

Good luck!
Andrew



More information about the Digitalmars-d mailing list