1

I'm working on integrating my current game engine with the irrKlang sound engine, and am dealing with a persistent error. Simplified:

fsCore.h

class fsEngine
{
public:
    static fsEngine *getInstance();
    static void release();
    ;
private:
    static fsEngine *instance;
    static fsBool exists;
    irrklang::ISoundEngine *soundEngine;
};

fsCore.cpp

#include "fsCore.h"
void fsEngine::release()
{
    exists = false;
    delete instance;
    soundEngine->drop(); //C2227
};

The engine is being declared correctly, and the singleton is performing as expected. Any ideas?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Catsup
  • 13
  • 1
  • 4

1 Answers1

4

Explanation of C2227 can be found here: Compiler Error C2227.

When the compiler gets to this line:

soundEngine->drop(); //C2227

it tells you that soundEngine must be pointer to class / struct / union in order to call drop() on it. The actual problem here is that you're trying to access the non-static data member from static function.

Also note that delete doesn't changes the value of pointer itself, so after this line is executed:

delete instance;

the value of instance is still set to the same address, this pointer has became invalid (dangling). It is a good practice to assign NULL to the pointer after you delete it:

delete instance;
instance = NULL;
LihO
  • 41,190
  • 11
  • 99
  • 167
  • Ah thank you. Does that mean I can't access static variables from a non-static function? LNK2001. – Catsup May 02 '13 at 18:25
  • 1
    @Catsup: Accessing static members from a non-static member function is perfectly OK. – LihO May 02 '13 at 18:37
  • the link error was from attempting to access the static variable from outside the file it was created in. – Catsup May 03 '13 at 16:58