首页  

c++ 变量名 冲突     所属分类 c 浏览量 659
#include "iostream"
using namespace std;

long count = 0;

int main(){
    cout << count << endl;
}


编译报错

name_conflic.cpp:7:13: error: reference to 'count' is ambiguous
    cout << count << endl;
            ^
name_conflic.cpp:4:6: note: candidate found by name lookup is 'count'
long count = 0;
     ^

全局变量 count 与 std::count 冲突

解决方法
去掉  using namespace std; 
或者  使用全局变量count 加前缀  ::
cout << ::count << endl;

建议 不要使用  using namespace xxx;

上一篇     下一篇
c++模板和java泛型

c++11 线程实例

NULL 与 nullptr

c++ rapidjson 使用

大端和小端模式

c++ header-only library