2

I've seen many people regarding them as the same,like unnamed(anonymous) namespace definition

However,there actually seems to be some difference between them,like Are “anonymous structs” standard? And, really, what are they?

As far as I'm concerned,both of them have no name,it seems hard to me to distinguish them from the semantic.

For example,the lambda is a unnamed object of an unnamed class,can we just say lambda is a anonymous object of an anonymous class?

choxsword
  • 3,187
  • 18
  • 44
  • I think that your question is hard to answer. It depends on the context. An unnamed or anonymous class are different, but for namespaces it doesn't matter. – Rakete1111 Mar 18 '18 at 15:12
  • The word "anonymous" actually means "without a name". They mean the same thing. But, terminology tends to be settled by history, or the standard into using one or the other for different things. Hence *anonymous struct* means a `struct` without a *type name*. We tend to say *unnamed temporary* for compiler generated variables. – Galik Mar 18 '18 at 15:38
  • 1
    If you search the C++ standard for the term "anonymous namespace" you won't find any matches. If you search for "unnamed namespace" you will find matches. Using the right technical term is important; using terminology that is derived from a pun can be confusing. – Pete Becker Mar 18 '18 at 16:18
  • @PeteBecker So there is no term of "anonymous" in the standard,except the "anonymous struct"? – choxsword Mar 19 '18 at 03:45
  • There are no anonymous structs (that's a Microsoft thing). There are anonymous unions and anonymous bit-fields. – Pete Becker Mar 19 '18 at 12:20

0 Answers0