Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:33:29+00:00 2026-05-16T15:33:29+00:00

Motivated by the discussion The grammar for C++ classes is defined as class-key identifier

  • 0

Motivated by the discussion

The grammar for C++ classes is defined as

class-key identifier *[opt]* base-clause *[opt]* (Italics are mine)

This to me means that the class name is option and we can have unnamed classes in C++.

So, is the following well-formed?

struct X{
   struct{
      int x;
      int y;
   };
};

int main(){}

VS: error C2467: illegal declaration
of anonymous ‘struct’

Comeau online: error: declaration does
not declare anything
struct{

GCC(ideone): Compiles fine

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:33:29+00:00Added an answer on May 16, 2026 at 3:33 pm

    No, it is not well-formed. You cannot derive the language syntax from these grammar statements alone. The extra requirements are given in the text of the standard also have to be taken into account. In this case that would be

    7 Declarations

    …

    3 In a simple-declaration, the optional init-declarator-list can be
    omitted only when declaring a class
    (clause 9) or enumeration (7.2), that
    is, when the decl-specifier-seq
    contains either a class-specifier, an
    elaboratedtype-specifier with a
    class-key (9.1), or an enum-specifier.
    In these cases and whenever a
    class-specifier or enum-specifier is
    present in the decl-specifier-seq, the
    identifiers in these specifiers are
    among the names being declared by the
    declaration (as class-names,
    enum-names, or enumerators, depending
    on the syntax). In such cases, and
    except for the declaration of an
    unnamed bit-field (9.6), the
    decl-specifier-seq shall introduce one
    or more names into the program, or
    shall redeclare a name introduced by a
    previous declaration
    .

    The last sentence is the one that matters in this case

    The "optional" part is only there to allow declarations like

    struct { int x; } s;
    typedef struct { int x, y; } Point;
    

    The first one which declares a class type with no linkage and variable s of that type. Note that types with no linkage cannot be used to declare a variable with linkage, meaning that such declaration cannot be used in namespace scope.

    Your example is ill-formed, but this would be legal

    struct X {
       struct {
          int x;
          int y;
       } point;
    };
    

    Also, nameless class syntax is used to declare anonymous unions (although I’m a bit puzzled by the fact that 7/3 does not mention anonymous unions).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is motivated by something I've lately started to see a bit too
Motivated by this answer I was wondering what's going on under the curtain if
[This question is motivated by Chapter 9 in Real World Haskell] Here's a simple
If you are motivate to the "pros" of an ORM and why would you
McCarthy's original Lisp and some number of incarnations thereafter did not have a macro
I wanted to study how modern sites (Facebook, Twitter, digg.com, Flickr, etc...) scaled their
I am going to attempt to teach some iphone application development at my job,
VB.NET 2010, .NET 4 Hello, I recently read about using SynchronizationContext objects to control
Am attempting to teach myself to program using Tcl. The task i've set myself
Am attempting to teach myself to program using Tcl. (I want to become more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.