Casting pointers
Deewiant
deewiant.doesnotlike.spam at gmail.com
Sat Jul 7 10:04:02 PDT 2007
Henning Hasemann wrote:
> FYI the construct was something like this (note that I'm too lazy to
> work out the correct casting again, I'll just show the basic idea):
>
> class MainLoop {
> IRenderable*[] renderables;
> // render the renderables in a method
> }
>
> class UserInterface : IRenderable {
> }
>
> class Scene : IRenderable {
> }
>
> UserInterface globalUserInterface;
> Scene currentScene;
>
> MainLoop mainLoop;
> mainLoop.renderables ~= &globalUserInterface;
> mainLoop.renderables ~= ¤tScene;
>
> // some time later:
> currentScene = someOtherScene;
> // and/or:
> globalUserInterface = specialUserInterfaceForMiniGame;
>
The thing about D is that interfaces and classes are already reference types.
IRenderable* here is equivalent to IRenderable** in C++. For your code above,
using just IRenderable would have worked just fine.
--
Remove ".doesnotlike.spam" from the mail address.
More information about the Digitalmars-d
mailing list