Where are the template members?

Rene Zwanenburg renezwanenburg at gmail.com
Wed Dec 5 09:54:05 PST 2012


On Wednesday, 5 December 2012 at 08:39:12 UTC, Gor Gyolchanyan 
wrote:
> Consider this piece of code:
>
> struct Test
> {
> template member(Type)
> {
> Type member;
> }
> }
>
> unittest
> {
> Test test;
> test.member!int = 0;
> test.member!long = 0;
> test.member!short = 0;
> import std.stdio; writeln(test.sizeof);
> assert(test.sizeof == int.sizeof + long.sizeof + short.sizeof); 
> // fails
> assert(test.sizeof == 1); // succeeds
> }
>
> I don't get why the structure's size remains unchanged even 
> after
> instantiating 3 members inside it.
> How can I get the real size of the structure, including all its 
> members
> (template or not)?

Isn't this an accepts invalid bug?

I don't see how it would be possible to add instance variables to 
a class or struct using templates...


More information about the Digitalmars-d mailing list