2015-02-05 103 views
-1
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall Sounds::soundBox(void)" ([email protected]@@QAEXXZ) referenced in function _main  

由於某種原因我得到這個錯誤,我真的不知道我做錯了什麼。 了wimm.lib添加playsound工作從主() 當我嘗試從類調用它playsound.cpp它調用錯誤...CPP錯誤LNK2019:無法解析的外部符號cpp

playsounds.h

#pragma once 
#include <Windows.h> 

class Sounds 
{ 
public: 
Sounds(); 
~Sounds(); 

void soundBox(); 
}; 

playsound.cpp調用時

#include "playsound.h" 

Sounds::Sounds() 
{ 

} 

void soundBox() 
{ 
PlaySound(TEXT("fx/boom1.wav"), NULL, SND_FILENAME); 
} 


Sounds::~Sounds() 
{ 

} 

的main.cpp

#include <iostream> 
#include <conio.h> 
#include "playsound.h"  

int main() 
{ 
Sounds newsound; 

newsound.soundBox(); 

_getch(); 
} 
+1

在@πάνταῥεῖ發佈的鏈接中,請看[特意此處](http://stackoverflow.com/a/12574407/2296458) – CoryKramer 2015-02-05 18:12:04

+0

奇怪的是,您已經正確地爲'聲音:: Sounds()'和'Sounds ::〜Sounds()',是由IDE生成的嗎? – 2015-02-05 18:14:59

回答

1

你的東東d改變函數定義playsound.cpp

void soundBox() 

void Sounds::soundBox() 

這是因爲該功能Sounds類的範圍內存在,所以你必須把它定義爲這樣的。否則,它將是一個免費函數,並且您的Sounds類中的函數版本將不確定(這是錯誤告訴您的)。

+0

Thx男人,我這樣做,但在標題...這解釋了一切。 – Mefiq 2015-02-05 18:25:41

相關問題