struct constructor co nfusion
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 6 22:34:58 PST 2015
On 06.11.2015 20:05, Spacen Jasset wrote:
> Also, I had to add a dummy private constructor to make my structs
> 'createable', or is there another way?
>
> e.g.
>
> struct Texture
> {
> @disable this();
> static Texture create()
> {
> return Texture(0);
> }
>
> ...
>
> private:
> this(int)
> {
> glGenTextures(1, &textureId_);
> enforce(0 != textureId_);
> }
>
> GLuint textureId_;
> }
You can use Texture.init to initialize a variable:
----
struct Texture
{
@disable this();
static Texture create()
{
Texture t = Texture.init;
glGenTextures(1, &t.textureId_);
enforce(0 != t.textureId_);
return t;
}
private:
GLuint textureId_;
}
----
More information about the Digitalmars-d-learn
mailing list