Base class with member parameterized on type of extending class
rcor via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Oct 20 03:27:50 PDT 2014
On Monday, 20 October 2014 at 06:17:42 UTC, Jacob Carlborg wrote:
>
> You can always make Scene a template class:
>
> abstract class Scene (T)
> {
> private StateMachine!T _stateMachine;
> }
>
> class MainMenu : Scene!(MainMenu) {}
>
> But I'm guessing you like to avoid that if possible.
I would, as I need to keep track of the current scene in a
variable somewhere:
Scene _currentScene; // problematic if Scene is a template
I could just declare the StateMachine separately in every Scene,
but that seems like a lot of duplicate code (I then repeat the
same code for updating the state machine, ect.)
More information about the Digitalmars-d-learn
mailing list