标题:两个文件其中的namespace的含义 求解答
取消只看楼主
新人学习
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:145
专家分:187
注 册:2017-10-26
结帖率:66.67%
 问题点数:0 回复次数:0 
两个文件其中的namespace的含义 求解答
//第一个文件
#include<iostream>
using namespace std;
void other();
void another();
int x = 10;
int y;

int main()
{
    cout << x << endl;
    {
        int x = 4;
        cout << x << endl;
        cout << y << endl;
    }
    other();
    another();

    system("pause");
    return 0;
}
void other()
{
    int y = 1;
    cout << "Other: " << x << ", " << y << endl;
}
//第二个文件
#include<iostream>
using namespace std;
extern int x;
namespace
{
    int y = -4;

}

void another()
{
    cout << "another(): " << x << ", " << y << endl;
}

//为什么最后一行输出Y的值是-4?namespace 起到了什么作用????

[此贴子已经被作者于2018-1-16 11:19编辑过]

搜索更多相关主题的帖子: 文件 namespace void int cout 
2018-01-16 11:17



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




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

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