[英]Attribute “deprecated” to namespace in C++17
I have created C++ program to experiment of deprecated
keyword of C++17. 我创建了C ++程序来试验C ++ 17
deprecated
关键字。
It's working fine in clang(3.8.0) , But, g++(5.4.0) gives an error. 在clang(3.8.0)中工作正常,但是g ++(5.4.0)给出了错误。
source_file.cpp:9:11: error: expected identifier before ‘[’ token
namespace [[ deprecated ]] bar
^
source_file.cpp:9:28: error: ‘bar’ does not name a type
namespace [[ deprecated ]] bar
^
source_file.cpp: In function ‘int main()’:
source_file.cpp:16:5: error: ‘bar’ has not been declared
bar::var = 10;
Why? 为什么?
#include <iostream>
using namespace std;
namespace foo
{
int var;
}
namespace [[ deprecated ]] bar
{
int var;
}
int main()
{
bar::var = 10;
return 0;
}
The clue is in the error message: "expected identifier before [
token". 提示位于错误消息中:“
[
标记之前的预期标识符 ”。 The identifier is bar
, and it has to appear before [
. 标识符为
bar
,它必须出现在 [
。 So: 所以:
namespace bar [[deprecated]]
{ }
Tested with GCC6.3 经过GCC6.3测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.