error LNK2001: unresolved external symbol \"private: static class

拈花ヽ惹草 提交于 2019-12-03 05:24:22

Put this into sound.cpp:

irrklang::ISoundEngine* Sound::_soundDevice;

NOTE: You might want to initialize it as well, for example:

irrklang::ISoundEngine* Sound::_soundDevice = 0;

static, but non-const data members should be defined outside of the class definition and inside the namespace enclosing the class. The usual practice is to define it in the translation unit (*.cpp) because it is considered to be an implementation detail. Only static and const integral types can be declared and defined at the same time (inside class definition):

class Example {
public:
  static const long x = 101;
};

in this case you don't need to add x definition because it is already defined inside the class definition. However, in your case it is necessary. Extract from section 9.4.2 of the C++ Standard:

The definition for a static data member shall appear in a namespace scope enclosing the member’s class definition.

David A. Gray

Eventually, the answer given by @Alexander resolved a similar issue in my own code, but not without a few trials. For the benefit of the next visitor, when he says "Put this into sound.cpp," to be perfectly clear, this is in addition to what is already present in sound.h.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!