请问一个关于命名空间中变量冲突的问题
#include <iostream>#include "my.h"
using namespace std;
using namespace myspace;
extern void output();
int main()
{
output();
return 0;
}
#include <iostream>
#include "my.h"
using namespace std;
using namespace myspace;
void output()
{
cout << "verbose = " << verbose << endl;
}
#ifndef _MY_H
#define _MY_H
namespace myspace {
bool verbose = true;
};
#endif
[xx@localhost cppwork]$ g++ a.cpp b.cpp
/tmp/ccRPtZqX.o:(.data+0x0): multiple definition of `myspace::verbose'
/tmp/ccgNbGeR.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
我想在a.cpp 和b.cpp中都使用verbose这个变量,但是出现冲突定义问题,请问如何解决,非常感谢!!