一个unresolved external的问题
acqy 2006-08-01 10:33:22 我的代码如下:
// ------------ test.h
#ifndef __TEST_H
#define __TEST_H
#ifdef __cplusplus
extern "C" {
#endif
class Test
{
protected:
unsigned short mp_port;
public:
virtual unsigned short GetPort();
virtual void SetPort(unsigned short port);
}
#ifdef __cplusplus
}
#endif
#endif
// ------------- test.cpp
#include "test.h"
unsigned short Test::GetPort()
{
return mp_port;
}
void Test::SetPort (unsigned short port)
{
mp_port = port;
}
现在的问题是:链接后仅在SetPort函数上出现unresolved external的错误,而GetPort函数却没有问题。
如果将SetPort函数更名为其它的名称,例如FF或者任何名称,就可以编译通过
如果将SetPort的实现搬到.h文件中,同样也可以编译通过。
请问高手,这是什么原因呢?