关于预编译的问题
//Error.h
#ifndef XXX_ERROR
#define XXX_ERROR
extern int no_of_errors; // note: default initialized to 0
#endif
double error(const char* s);
//Error.cpp
#include"Error.h"
#include<iostream>
double error(const char* s)
{
no_of_errors++;
std::cerr << "error: " << s << '\n';
return 1;
}
//main.cpp
#include<iostream>
#include"Error.h"
int main(int argc, char* argv[])
{
error("There is a Error!");
return no_of_errors;
}
这个程序错在那里?
出错信息:
Linking...
test.obj : error LNK2005: "int no_of_errors" (?no_of_errors@@3HA) already defined in Error.obj
Debug/Test.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
麻烦大哥们帮我看一下.