Not sure how to translate this C++ variable to D.
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 14 15:19:50 PDT 2016
On 03/14/2016 03:14 PM, WhatMeWorry wrote:
>
> -------------------- sprite_renderer.h --------------
>
> class SpriteRenderer
> {
> ...
> };
Same thing in D without the semicolon. :)
> -------------------- game.cpp ------------------------
>
> #include "sprite_renderer.h"
>
> SpriteRenderer *Renderer;
Like in Java and C#, class variables are object references in D. So, the
following is sufficient:
SpriteRenderer Renderer; // Although, I would name it 'renderer'
However, unlike C++, that variable is thread-local, meaning that if you
have more than one thread, each will have their own variable. If you
really need it, in multithreaded code you may want to define it shared:
shared(SpriteRenderer) renderer;
But then you will have to deal with thread synchronization.
> I tried taking due diligence with the documentation.
There is something here:
http://ddili.org/ders/d.en/class.html#ix_class.variable,%20class
Ali
More information about the Digitalmars-d-learn
mailing list