class grammar

Nick my_dlang at bestmail.us
Fri May 7 18:07:45 UTC 2021


The class grammar, as defined in the D language specification 
([Classes](https://dlang.org/spec/grammar.html#classes)), seems 
to imply that a class can inherit from a fundamental type. 
Explicitly, the specification says that a 'SuperClass' is a 
'BasicType'. And a 'FundamentalType' is a 'BasicType'.

However, when I attempt to compile the following declaration, I 
get an error.

```d
class A : int {}
```

```d
Error: class `test.A` base type must be `class` or `interface`, 
not `int`
```

After reading the grammar for a 'BasicType' 
([BasicType](https://dlang.org/spec/type.html#BasicType)), it is 
not clear to me how a user-defined type (such as a class or 
interface) is also a 'BasicType' (as defined by the grammar). 
However, the compiler only accepts classes or interfaces as a 
base type.

How am I misunderstanding the specification?


More information about the Digitalmars-d-learn mailing list