digitalmars.D.learn - Error: no property "someFont" for type int
- Marco de Wild (33/33) Nov 10 2015 I'm trying to build a small manga reader application (because why
- Mike Parker (19/33) Nov 10 2015 This is not D. It should be giving you a compiler error. How are
- Mike Parker (2/3) Nov 10 2015 And of course, I meant dsfml.graphics.text.
- Marco de Wild (7/31) Nov 11 2015 I indeed made a typo while typing the post (and also on various
I'm trying to build a small manga reader application (because why search the internet if you can build it yourself), using DSFML. However, I'm getting a weird compilation error that I can't decrypt. In directory.d: using style; (...) _text = new Text; with(_text) { setFont(Style.DirectoryFont); In style.d: module style; (...) public static class Style { private static Font _font; public static Font DirectoryFont() { if(!(_font is null)) return _font; _font = new Font; Load(_font); // Helper function that loads the font into _font return _font; } } I'm getting the error message that the compiler can't find source/directory.d(...) : Error: no property 'DirectoryFont' for type 'int'. When I change the line to actually contain the (iirc optional) brackets, the type changes to 'Style'. Am I missing something with regards to static classes and members in D? Thanks in advance.
Nov 10 2015
On Wednesday, 11 November 2015 at 06:37:44 UTC, Marco de Wild wrote:In directory.d: using style;This is not D. It should be giving you a compiler error. How are you compiling? Or did you type 'using' in the post by mistake? Anyway, what you want is: import style;In style.d: module style; (...) public static class Style {'static class' has no meaning in module scope, only for inner classes. It's not the cause of your problem though.I'm getting the error message that the compiler can't find source/directory.d(...) : Error: no property 'DirectoryFont' for type 'int'. When I change the line to actually contain the (iirc optional) brackets, the type changes to 'Style'. Am I missing something with regards to static classes and members in D? Thanks in advance.The error is likley because of a symbol conflict. Assuming that Text is from the module dsfml.text.graphics, it has an enum type named Style. There's an unfortunate issue in D that allows both of the following to compile: auto e1 = Text.Style.Regular; _text.Style.Regular; The latter should not be allowed, IMO, but it is what it is. So in your case, accessing your Style class in the scope of with(_text) is causing the compiler to find _text.Style. The solution is to use the FQN (Fully Qualified Name) on your Style inside the with, i.e. style.Style, or to drop the with altogether.
Nov 10 2015
On Wednesday, 11 November 2015 at 07:46:31 UTC, Mike Parker wrote:Text is from the module dsfml.text.graphics, it has an enumAnd of course, I meant dsfml.graphics.text.
Nov 10 2015
This is not D. It should be giving you a compiler error. How are you compiling? Or did you type 'using' in the post by mistake? Anyway, what you want is: import style;I indeed made a typo while typing the post (and also on various occasions while writing the program, but compiler errors fixedThanks for the heads up :) I figured it was about time to dust my D-skills.In style.d: module style; (...) public static class Style {'static class' has no meaning in module scope, only for inner classes. It's not the cause of your problem though.The error is likley because of a symbol conflict. Assuming that Text is from the module dsfml.text.graphics, it has an enum type named Style. There's an unfortunate issue in D that allows both of the following to compile: auto e1 = Text.Style.Regular; _text.Style.Regular; The latter should not be allowed, IMO, but it is what it is. So in your case, accessing your Style class in the scope of with(_text) is causing the compiler to find _text.Style. The solution is to use the FQN (Fully Qualified Name) on your Style inside the with, i.e. style.Style, or to drop the with altogether.Dropping the with worked like a charm, thanks a lot for the fast reply!
Nov 11 2015