标题:请问一个关于命名空间中变量冲突的问题
取消只看楼主
blues1207
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-3-18
结帖率:0
已结贴  问题点数:20 回复次数:0 
请问一个关于命名空间中变量冲突的问题
#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这个变量,但是出现冲突定义问题,请问如何解决,非常感谢!!
搜索更多相关主题的帖子: 空间 变量 
2010-04-01 18:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-301333-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.006516 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved