当我尝试在Visual Studio 2010中构建项目时,出现以下错误:
1>WaveEditDoc.obj : error LNK2001: unresolved external symbol "public: static int CWaveEditView::selectionEnd" (?selectionEnd@CWaveEditView@@2HA)
1>WaveEditView.obj : error LNK2019: unresolved external symbol "public: static int CWaveEditView::selectionEnd" (?selectionEnd@CWaveEditView@@2HA) referenced in function "public: virtual void * __thiscall CWaveEditView::`scalar deleting destructor'(unsigned int)" (??_GCWaveEditView@@UAEPAXI@Z)
1>WaveEditDoc.obj : error LNK2001: unresolved external symbol "public: static int CWaveEditView::selectionStart" (?selectionStart@CWaveEditView@@2HA)
1>WaveEditView.obj : error LNK2019: unresolved external symbol "public: static int CWaveEditView::selectionStart" (?selectionStart@CWaveEditView@@2HA) referenced in function "public: virtual __thiscall CWaveEditView::~CWaveEditView(void)" (??1CWaveEditView@@UAE@XZ)
1>C:\Users\aottinge\Documents\CS390CPP\WaveEdit\Debug\WaveEdit.exe : fatal error LNK1120: 2 unresolved externals
在CWaveEditView中定义了 selectionStart
和selectionEnd
,我试图在WaveEditDoc类中的函数中访问它们。我没有编译错误,所以我知道我正在引用所有内容。以下是显然导致问题的代码部分:
void CWaveEditDoc::OnToolsPlay()
{
// TODO: Add your command handler code here
if(CWaveEditView::selectionStart!=CWaveEditView::selectionEnd){
WaveFile * selection = new WaveFile(wave.numChannels, wave.sampleRate, wave.bitsPerSample);
int i = CWaveEditView::selectionStart;
while(i<=CWaveEditView::selectionEnd){
selection->add_sample(wave.get_sample(i));
}
selection->play();
delete selection;
}else{
wave.play();
}
}
答案 0 :(得分:3)
您没有获得编译器错误这一事实意味着编译器已经看到了selectionStart和selectionEnd的声明并且检查了所有类型
您收到链接器错误,因为这些符号中没有实际的定义。
明显的问题:selectionStart和selectionEnd的定义在哪里 - 你是否链接了Doc&amp;一起查看对象文件,以便链接器可以将外部符号与其定义匹配?