gpt4 book ai didi

c++ - 在一个函数中使用 namespace 中的符号,但在同一文件中不使用另一个 namespace 中的符号

转载 作者:行者123 更新时间:2023-12-03 18:33:39 25 4
gpt4 key购买 nike

我必须在同一个命名空间和同一个文件中定义两个函数,比如说,foo()bar()。对于第一个 foo() 的定义,我想使用 namespace other 的所有符号,但不想要来自 namespace other 的符号 自动在我的其他函数 bar() 的范围内。这可能吗?怎么办?

(注意:我不想知道替代“解决方案”或者避免缓解这个问题,例如 namespace o=other 等)

最佳答案

是的,这是可能的:

void foo()
{
using namespace abc;
....
}

void foo()
{
using abc::x;
using abc::y;
using abc::z;
....
}

关于c++ - 在一个函数中使用 namespace 中的符号,但在同一文件中不使用另一个 namespace 中的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23568684/

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