What is the scope of a namespace alias in C++?

2019-06-15 01:51发布

Does a C++ namespace alias defined inside a function definition have a block, function, file, or other scope (duration of validity)?

7条回答
ら.Afraid
2楼-- · 2019-06-15 02:26

As far as I know, it's in the scope it's declared. So, if you alias in a method, then it's valid in that method, but not in another.

查看更多
做个烂人
3楼-- · 2019-06-15 02:27

I'm fairly certain that a namespace alias only has scope within the block it's created in, like most other sorts of identifiers. I can't check for sure at the moment, but this page doesn't seem to go against it.

查看更多
淡お忘
4楼-- · 2019-06-15 02:28

It's a block duration of validity. E.g If you define a namespace alias as below, the namespace alias abc would be invalid outside {...} block.


 {  
    namespace abc = xyz;
    abc::test t;  //valid 
 }
  abc::test t;  //invalid

查看更多
Anthone
5楼-- · 2019-06-15 02:32

It would have the scope of the block in which it was defined - likely to be the same as function scope unless you declare the alias inside a block within a function.

查看更多
在下西门庆
7楼-- · 2019-06-15 02:52

The scope is the declarative region in which the alias is defined.

查看更多
登录 后发表回答