www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - .sizeof on templates needs extra parens?

reply C. Dunn <cdunn2001 gmail.com> writes:
Why do I need extra parentheses to get template.sizeof?

class A(T){
  T x;
};

int y = (A!(int)).sizeof;
int z = A!(char).sizeof; // does not compile (line 6)

hello.d(6): Error: undefined identifier class A.sizeof
hello.d(6): Error: cannot implicitly convert expression (class A.sizeof) of
type void to int
Jul 31 2007
parent reply BCS <BCS pathlink.com> writes:
C. Dunn wrote:
 Why do I need extra parentheses to get template.sizeof?
 
 class A(T){
   T x;
 };
 
 int y = (A!(int)).sizeof;
 int z = A!(char).sizeof; // does not compile (line 6)
 
 hello.d(6): Error: undefined identifier class A.sizeof
 hello.d(6): Error: cannot implicitly convert expression (class A.sizeof) of
type void to int

keep in mind that class Name(args) is actually just shorthand for template A(T){ class A{ T x; } } A!(int) -> A!(int).A A!(int).sizeof -> A!(int).sizeof // doesn't exits
Aug 01 2007
parent C. Dunn <cdunn2001 gmail.com> writes:
That makes sense.  Thanks.
Aug 01 2007