【发布时间】:2011-04-08 21:40:41
【问题描述】:
可能重复:
What is an undefined reference/unresolved external symbol error and how do I fix it?
为什么以下代码出现“未定义对Monitor::count 的引用”错误?谢谢!
#include <iostream>
using namespace std;
class Monitor
{
static int count;
public:
void print() { cout << "incident function has been called " << count << " times" << endl; }
void incident() { cout << "function incident called" << endl; count++; }
};
void callMonitor()
{
static Monitor fooMonitor;
fooMonitor.incident();
fooMonitor.print();
}
int main()
{
for (int i = 0; i < 5; i++)
callMonitor();
return 1;
}
【问题讨论】: