gpt4 book ai didi

C++ : multiple namespaces inside a function

转载 作者:行者123 更新时间:2023-11-30 04:17:02 24 4
gpt4 key购买 nike

<分区>

我正在尝试下面的代码,在一个函数中使用多个命名空间(更改命名空间)。我不确定哪里出了问题,我什至不确定我是否可以像下面这样使用,但在我短暂的浏览中没有找到任何矛盾的证据,请告诉我哪里出了问题:

#include <iostream>
using namespace std;

namespace standard_one
{
int i = 10;
}

namespace standard_two
{
int i = 40;
}


main()
{
using namespace standard_one;
cout << "value of i is " << i << endl;

{
using namespace standard_two;
cout << "value of i after namespace change is " << i << endl; // Compilation error here, compiler is complaining that "i" is undeclared
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com