www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simple call to static member function

reply WhatMeWorry <kheaser gmail.com> writes:
--------------- 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
next sibling parent tsbockman <thomas.bockman gmail.com> writes:
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
prev sibling parent reply ag0aep6g <anonymous example.com> writes:
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
parent WhatMeWorry <kheaser gmail.com> writes:
On Friday, 11 March 2016 at 23:14:48 UTC, ag0aep6g wrote:
 On 11.03.2016 23:47, WhatMeWorry wrote:
 [...]
This suggests that you simply `import ResourceManager;` in main.d. [...]
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.
Mar 11 2016