C++ 中的标识符不能是关键字,可以吗?
Identifier in C++ cannot be a keyword, can it?
我可以用以下关键词来形容我当下的心情:
public 这个新的私有保护案例尝试抛出长假签名联合或不是朋友删除双自动 class 和 return 使用真虚拟的短静态中断volatile while do default export if register catch else float
这些关键字是标识符吗?我的问题是我可以将它们用于重新定义或重载吗?不,但为什么不呢? "The standard reserved keywords that cannot be used for programmer created identifiers are: ..." - 对不起?!这是什么意思?我不明白为什么他们给了我一些关键字并告诉我不要使用它们。那我应该使用什么标识符?
感谢您的回答!
这意味着您不能声明变量、函数和 类 将这些关键字之一作为名称。但如果你按原样使用它们,一切都很好。例如,关键字 "for" 不能用作变量,即你不能有像
这样的东西
int for = 4; // Wrong!
但它可以(而且必须!)用于启动 for 循环。
其他语言使用sigils解决了这个问题。 C++ 没有,因此不能从保留关键字列表中选择可用于标识符的名称。
Are these keywords identifiers?
不,关键字不是标识符。
they gave me some keywords and tell me not to use them. What identifiers should I use then?
对于标识符,您必须使用不是关键字的任意词。
举个例子更容易解释。
考虑这一行:
int foo = 42;
这里,int
是关键字。此行使 foo
成为标识符。
但是,这一行:
int friend = 42;
格式不正确(即无法编译),因为它试图使关键字 (friend
) 成为标识符。
我可以用以下关键词来形容我当下的心情:
public 这个新的私有保护案例尝试抛出长假签名联合或不是朋友删除双自动 class 和 return 使用真虚拟的短静态中断volatile while do default export if register catch else float
这些关键字是标识符吗?我的问题是我可以将它们用于重新定义或重载吗?不,但为什么不呢? "The standard reserved keywords that cannot be used for programmer created identifiers are: ..." - 对不起?!这是什么意思?我不明白为什么他们给了我一些关键字并告诉我不要使用它们。那我应该使用什么标识符?
感谢您的回答!
这意味着您不能声明变量、函数和 类 将这些关键字之一作为名称。但如果你按原样使用它们,一切都很好。例如,关键字 "for" 不能用作变量,即你不能有像
这样的东西int for = 4; // Wrong!
但它可以(而且必须!)用于启动 for 循环。
其他语言使用sigils解决了这个问题。 C++ 没有,因此不能从保留关键字列表中选择可用于标识符的名称。
Are these keywords identifiers?
不,关键字不是标识符。
they gave me some keywords and tell me not to use them. What identifiers should I use then?
对于标识符,您必须使用不是关键字的任意词。
举个例子更容易解释。
考虑这一行:
int foo = 42;
这里,int
是关键字。此行使 foo
成为标识符。
但是,这一行:
int friend = 42;
格式不正确(即无法编译),因为它试图使关键字 (friend
) 成为标识符。