On Tue, May 03, 2022 at 04:59:42PM +0000, cc via Digitalmars-d-learn wrote:
> On Tuesday, 3 May 2022 at 16:51:33 UTC, H. S. Teoh wrote:
[...]
> > > On Tuesday, 3 May 2022 at 15:08:53 UTC, H. S. Teoh wrote:
> > > >         class Base : Serializable!(Base) { ... }
> > > >         class Derived : Serializable!(Base, Derived) { ... }
[...]
> Hm although I am having trouble with that particular implementation:
> ```d
> class Base : Serializable!(Base) {}
> class Derived : Serializable!(Base, Derived) {}
> class Serializable(Base, Derived = Base) : Base {}
> ```
> ```
> Error: class `test.Base` circular inheritance
> Error: template instance `test.Serializable!(Base, Base)` error
> instantiating
> ```

Oops, sorry, I made a mistake. The definition of Serializable should be:

        class Serializable(Base, Derived = Object) : Base {}

and the corresponding static if in the implementation should test for
Object instead of Base.  Basically, it's just some way of
differentiating the base class from the derived classes, because you
need to declare the serialize methods in the base class without
`override` but in the derived classes you need `override`.


T

-- 
Turning your clock 15 minutes ahead won't cure lateness---you're just making 
time go faster!

Reply via email to