-14

I can describe my moment mood with the following keywords:

this new private protected case for public try throw long false signed union or not friend delete double auto class and return short static break using true virtual volatile while do default export if register catch else float

Are these keywords identifiers? My question is can I use these with re-definition or overloading? No. But why not? "The standard reserved keywords that cannot be used for programmer created identifiers are: ..." - Excuse me?! What does it means? I can't understand why they gave me some keywords and tell me not to use them. What identifiers should I use then?

Thanks for the answering!

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207

2 Answers2

4

Are these keywords identifiers?

No, keywords are not identifiers.

they gave me some keywords and tell me not to use them. What identifiers should I use then?

For identifiers you have to use arbitrary words that are not keywords.

It's easier to explain with an example.
Consider this line:

int foo = 42;

Here, int is a keyword. This line makes foo an identifier.
However, this line:

int friend = 42;

would be ill-formed (i.e. wouldn't compile), as it tries to make a keyword (friend) an identifier.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • 1
    Keywords are identifiers. C++14 2.12p1: `The identifiers shown in Table 4 are reserved for use as keywords ...` They are separate tokens (groups?), but are identifiers too. – KamilCuk Dec 08 '18 at 21:54
  • 1
    @KamilCuk Huh. I interpret that as "Identifiers with the names listed below can't be created as those names are reserved for keywords"... I'd say it warrants a separate question. – HolyBlackCat Dec 08 '18 at 21:58
  • 1
    @KamilCuk Identifiers can be reserved to be used as keywords but keywords are not identifiers. – Galik Dec 08 '18 at 21:58
  • 1
    @KamilCuk Maybe a better way to put it is "The identifiers shown in Table 4 are not allowed to be used as identifiers because they are reserved for use as keywords" – Galik Dec 08 '18 at 22:06
  • 1
    @Galik - that is a contradictory statement. "identifiers in ... are not allowed to be used as identifiers". In any event, the standards are quite clear - some identifiers are keywords and some keywords cannot be used as identifiers. This means that the set of keywords and the set of identifiers intersect, but neither is a complete subset of the other. Which also means this answer is incorrect. – Peter Dec 09 '18 at 00:22
3

What it means is that you are not allowed to declare variables, functions and classes having one of those keywords as name. But if you use them for what they are, everything is fine. For example, the keyword "for" can't be used as a variable, i.e. you can't have something like

int for = 4; // Wrong!

but it can (and must!) be used to start a for loop.

Other languages solve this problem by using sigils. C++ doesn't, so the names that you can use for your identifiers can't be chosen from the list of reserved keywords.