www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - class MyClass(T) : Base if (ConstraintExpression) {} compilation error

reply "ref2401" <refactor24 gmail.com> writes:
Version D 2.062

Please explain what is causing the error

class Base
{ }

class Class(T) : Base
if (is(T == int))
{ }

Error: unrecognized declaration
Error: members expected
Error: Declaration expected, not 'if'
Error: { } expected following aggregate declaration
May 24 2013
next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On 2013-05-24, 16:49, ref2401 wrote:

 Version D 2.062

 Please explain what is causing the error

 class Base
 { }

 class Class(T) : Base
 if (is(T == int))
 { }

 Error: unrecognized declaration
 Error: members expected
 Error: Declaration expected, not 'if'
 Error: { } expected following aggregate declaration
I'm confused too. This works: class Base { } class Class(T) if (is(T == int)) : Base { } void foo() { Base a = new Class!int; } -- Simen
May 24 2013
prev sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Friday, 24 May 2013 at 14:49:24 UTC, ref2401 wrote:
 Version D 2.062

 Please explain what is causing the error

 class Base
 { }

 class Class(T) : Base
 if (is(T == int))
 { }

 Error: unrecognized declaration
 Error: members expected
 Error: Declaration expected, not 'if'
 Error: { } expected following aggregate declaration
because dmd acts as grammar nazi: ClassTemplateDeclaration: class Identifier ( TemplateParameterList ) Constraintopt BaseClassListopt ClassBody
May 24 2013