Simple call to static member function

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Mar 11 15:14:48 PST 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.


More information about the Digitalmars-d-learn mailing list