【发布时间】:2009-03-01 05:54:12
【问题描述】:
我正在尝试在 Visual Studio 2008 中构建一个项目。我遇到了一堆真正困扰我的链接器错误。我的应用程序是仅使用本机 ANSI C++ 的 Win32 控制台应用程序。
它们都是相同模式的链接器错误。 链接器错误与我在自己的头文件中定义的类的每个私有静态数据成员有关。
我猜这可能是我还不知道的 c++ 的一个简单事实?
示例: 我在文件Delays.cpp 中引用SingleDelay 成员类的函数定义中的SingleDelay 成员。 即:
SingleDelay::tick(void *output, void *input, int nbufferFrames)<br>{
//.. code here<br>
x = dry * castInput + wet * castInput;<br>
}
错误 38 错误 LNK2001: 无法解析的外部符号“private: static double SingleDelay::dry” (?dry@SingleDelay@@0NA) Delays.obj testall
Delays.h中SingleDelay的定义:
class SingleDelay{
private:
static double dry; //% of dry signal<br>
static double wet; //% of wet signal<br>
static unsigned int delay; //Delay in milliseconds<br>
static int delayCell; //Index in the delayBuffer of the delay to add<br>
static double *delayBuffer; //Delay buffer is 1 second long at sample rate SAMPLE_RATE<br>
static unsigned int bufferCell; //Pointer to the current delay buffer cell<br>
public:
//Tick function
static void tick(void *output, void *input,int nBufferFrames);
//Set and Get functions
static void setSingleDelay(double tDry, double tWet, unsigned int tDelay);
static void setSingleDelay(void);
static void setDry(double tDry);
static void setWet(double tWet);
static void setDelay(unsigned int tDelay);
static double getDry(){ return dry;}
static double getWet(){ return wet;}
static unsigned int getDelay(){ return delay;}
static void initializeDelayBuffer(){
destroyDelayBuffer();
delayBuffer = new double[bufferLength];
}
static void destroyDelayBuffer(){
delete[ ] delayBuffer;
}
};
【问题讨论】:
-
你能列出你得到的链接错误吗?
-
耶哈,您可能想发布确切的链接器错误,因此我们可以为您提供建议,可能是什么原因。
-
是的,我刚刚意识到,我添加了两个示例错误和一些相关代码。