c++ - Why does this code generate the compiler error C2227? -


i'm working on integrating current game engine irrklang sound engine, , dealing 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 being declared correctly, , singleton performing expected. ideas?

explanation of c2227 can found here: compiler error c2227.

when compiler gets line:

soundengine->drop(); //c2227 

it tells soundengine must pointer class / struct / union in order call drop() on it. actual problem here you're trying access non-static data member static function.

also note delete doesn't changes value of pointer itself, after line executed:

delete instance; 

the value of instance still set same address, pointer has became invalid (dangling). practice assign null pointer after delete it:

delete instance; instance = null; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -