Derelict SFML2 - structs are forward referenced
Rene Zwanenburg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 26 02:39:29 PST 2015
On Saturday, 26 December 2015 at 09:48:29 UTC, Lucien wrote:
> Hello.
>
> I want to use Derelict-SFML2 to create a simple window.
> But when I compile (linked with dub and derelict-util), I have
> the following error:
>
> src/app.d(30,20): Error: variable myproject.main.window no
> definition of struct sfRenderWindow
> ../../../.dub/packages/derelict-sfml2-3.0.1/source/derelict/sfml2/graphics.d(56,1): Error: struct derelict.sfml2.graphics.sfRenderWindow unknown size
> src/app.d(31,5): Error: struct sfRenderWindow is forward
> referenced
> src/app.d(32,12): Error: struct sfRenderWindow is forward
> referenced
> src/app.d(35,16): Error: struct sfRenderWindow is forward
> referenced
> src/app.d(38,17): Error: struct sfRenderWindow is forward
> referenced
>
> My code: http://pastebin.com/1svZAB22
>
> Is it a bug in Derelict-SFML2 or want did I do false ?
>
> Hoping that you understood me with my bad English :)
sfRenderWindow is an opaque struct, so its size is unknown. This
means you can only use pointers to them, and any operations on
them will have to be done using SFML. So in your code, change
sfRenderWindow to sfRenderWindow*.
Did you by any chance look at a C++ tutorial for SFML? Derelict
binds to the C API so it looks a bit different. To create a
window sfRenderWindow_create can be used, so lines 12 + 13 can be
replaced by
auto window = sfRenderWindow_create(sfVideoMode(200, 200), "SFML
works !");
Another example: the function to check if a window is open is
sfRenderWindow_isOpen, taking a pointer to an opaque
sfRenderWindow struct as first parameter. Due to D's so called
UFCS you can call this function in two ways:
sfRenderWindow_isOpen(window); // Just like in C
window.sfRenderWindow_isOpen(); // Use member-like syntax
More information about the Digitalmars-d-learn
mailing list