gpt4 book ai didi

c++ - 不允许 using 声明以不同名称访问函数名称是否有技术原因?

转载 作者:IT老高 更新时间:2023-10-28 22:17:34 26 4
gpt4 key购买 nike

考虑

namespace foo
{
namespace bar
{
void f();
void f(int);
}
}

foo 中,可以通过

将所有 foo::bar::f 作为 foo::f 访问
using bar::f; // in foo

不存在使所有 foo::bar::f 可以像 foo::g 一样访问的语法是否存在任何技术原因

using bar::f as g; 
// or in line with using declarations for types:
using g = bar::f;

或者类似的事情被考虑过但被拒绝了? (为什么?)

最佳答案

N1489 :

It is possible to generalize the notion of alias beyond types and namespaces to functions, variables, etc. We do not see sufficient benefits from doing this and can imagine serious overuse leading to confusion about which functions and variables are used. Consequently, we do not propose the generalizations mentioned in this section. Furthermore, we do not plan to work further on these generalizations unless someone comes up with examples that indicate significant usefulness.

关于c++ - 不允许 using 声明以不同名称访问函数名称是否有技术原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720244/

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