英文:
Is a using declaration for a non-member type equivalent to an alias declaration with an identifier equal to the terminal name of the using declarator?
问题
以下是翻译好的部分:
In short, I'm asking if doing
using foo::bar::baz;
has the same effect as
using baz = foo::bar::baz;
(Clearly I'm assuming that foo::bar::baz
names a type that is not a class member, e.g. I'm referring to something like namespace foo::bar { using baz = int; }
, and not to something like namespace foo { struct bar { using baz = int; }; }
.)
I'm pretty sure they are two different things (otherwise they could also always stay side by side, which is not the case, as I know that the former can't be in a struct
/class
, unlike the latter), but how do I read it from the standard? I was looking at [namespace.udecl] and [dcl.pre], but I can't really draw a conclusion.
英文:
In short, I'm asking if doing
using foo::bar::baz;
has the same effect as
using baz = foo::bar::baz;
(Clearly I'm assuming that foo::bar::baz
names a type that is not a class member, e.g. I'm referring to something like namesapce foo::bar { using baz = int; }
, and not to something like namespace foo { struct bar { using baz = int; }; }
.)
I'm pretty sure they are two different things (otherwise they could also always stay side by side, which is not the case, as I know that the former can't be in a struct
/class
, unlike the latter), but how do I read it from the standard? I was looking at [namespace.udecl] and [dcl.pre], but I can't really draw a conclusion.
答案1
得分: 1
代码部分不翻译,只返回翻译好的内容:
There are definitely differences between the two, but most of them are of no interest to most programmers. For example,
一个明显的区别是,两者之间存在差异,但其中大多数对大多数程序员来说都不感兴趣。例如,
One practical distinction is in exporting a previously declared name with module linkage:
一个实际的区别在于,导出以前声明的具有模块链接的名称:
The using-declaration can of course also be applied to non-type declarations, whereas the alias-declaration can also be a template.
using-declaration 当然也可以应用于非类型声明,而alias-declaration 也可以是一个模板。
英文:
There are definitely differences between the two, but most of them are of no interest to most programmers. For example,
namespace N {
struct X {};
struct Y {};
struct Z {};
}
namespace O {
int X,Y;
using N::X; // OK
struct X x; // OK, finds N::X
int i=X; // OK, finds O::X
using Y=N::Y; // error: conflicts with “int Y”
using Z=N::Z;
struct Z z; // error: elaborated-type-specifier with typedef-name
}
One practical distinction is in exporting a previously declared name with module linkage:
module A:S;
struct S {};
export module A;
import :S;
export using ::S; // error: “struct S” has module linkage
export using S=S; // OK
The using-declaration can of course also be applied to non-type declarations, whereas the alias-declaration can also be a template.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论