在我的课堂上,我有一个名为PlaySound(std::wstring)
的函数。此类位于其自己的命名空间中。当我试图从其他地方的实例调用此成员函数时,它会导致链接器错误,因为出于某种原因,它似乎试图调用PlaySoundW()
中定义的MMSystem.h
。我认为在我自己的命名空间中有东西是为了防止这种冲突?
链接器错误:
Error 13 error LNK2019: unresolved external symbol "public: void __thiscall MyNamespace::SoundProcessor::PlaySoundW(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?PlaySoundW@SoundProcessor@MyNamespace@@QAEXV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function "public: void __thiscall MyNamespace::Engine::Init(struct HWND__ *,long *,long *,int)" (?Init@Engine@MyNamespace@@QAEXPAUHWND__@@PAJ1H@Z)
我能理解的最好的一点是,我似乎在抱怨我在我的代码中使用PlaySoundW()
,但我没有在我的SoundProcessor
类中定义它。我的函数不是PlaySoundW()
。
我正在调用我的函数(从与声明函数的名称相同的名称空间中):
soundProcessor.PlaySound(TEXT("Sounds\\MySound.WAV"));
我希望这只是我错过的显而易见的东西。
答案 0 :(得分:0)
我的假设基于您获得的错误类型以及您的函数位于单独的命名空间中的事实是某处(可能在Microsoft包含)中存在以下代码段:
#ifdef _UNICODE
#define PlaySound PlaySoundW
#else
#define PlaySound PlaySoundA
#endif // _UNICODE
这些类型的#define
语句在microsoft的内部标头中很常见,因为它们旨在处理unicode和多字节字符编码。
为了解决此问题,您可能需要在使用代码之前添加以下内容:
#undef PlaySound