digitalmars.D.learn - Simple call to static member function
- WhatMeWorry (23/23) Mar 11 2016 --------------- main.d ------------------------
- tsbockman (4/6) Mar 11 2016 Please show enough of the code that I can actually try to compile
- ag0aep6g (16/34) Mar 11 2016 This suggests that you simply `import ResourceManager;` in main.d.
- WhatMeWorry (4/9) Mar 11 2016 Very good. Thanks for the fix and the pointers. I'm porting C++
--------------- main.d ------------------------ void main(string[] argv) { ResourceManager.LoadShader("VertexShader.glsl", "FragmentShader.glsl", "filler", "sprite"); --------------- File ResourceManager.d ------------------------ class ResourceManager { public: static void LoadShader(string vShaderFile, string ShaderFile, string gShaderFile, string name) { vShaderFile = "Do something"; // etc. } Keeps returning main.d(173): Error: undefined identifier 'LoadShader' in module 'ResourceManager' I'm sure I'm doing something really dumb here but I've been dealing with this for many hours and thought someone here could spot the problem in seconds. Thanks.
Mar 11 2016
On Friday, 11 March 2016 at 22:47:00 UTC, WhatMeWorry wrote:main.d(173): Error: undefined identifier 'LoadShader' in module 'ResourceManager'Please show enough of the code that I can actually try to compile it myself. In particular, I need to see how you handled the imports since that is likely where the problem lies.
Mar 11 2016
On 11.03.2016 23:47, WhatMeWorry wrote:--------------- main.d ------------------------ void main(string[] argv) { ResourceManager.LoadShader("VertexShader.glsl", "FragmentShader.glsl", "filler", "sprite"); --------------- File ResourceManager.d ------------------------ class ResourceManager { public: static void LoadShader(string vShaderFile, string ShaderFile, string gShaderFile, string name) { vShaderFile = "Do something"; // etc. } Keeps returning main.d(173): Error: undefined identifier 'LoadShader' in module 'ResourceManager'This suggests that you simply `import ResourceManager;` in main.d. Just `ResourceManager` is the module then. `ResourceManager.ResourceManager` would be the class. `ResourceManager.ResourceManager.LoadShader` would be the function. And `ResourceManager.LoadShader` doesn't exist, as there is no symbol `LoadShader` at module scope. Instead of using that long, repetitive name, you can use a selective import to have `ResourceManager` refer to the class instead of the module: `import ResourceManager: ResourceManager;`. By the way, module names are all lower-case by convention, mainly to avoid problems with case-insensitive file systems. That means, the source file would usually be called resourcemanager.d or resource_manager.d. That would also avoid the name clash. Also, a one-to-one relation between modules and classes is not usually followed in D. But if you want you can do that, of course.
Mar 11 2016
On Friday, 11 March 2016 at 23:14:48 UTC, ag0aep6g wrote:On 11.03.2016 23:47, WhatMeWorry wrote:Very good. Thanks for the fix and the pointers. I'm porting C++ code over, and it has corrupted me. I'll adopt all your suggestions.[...]This suggests that you simply `import ResourceManager;` in main.d. [...]
Mar 11 2016