1

I stumbled over a piece of syntax that I have not seen yet and didn't find online, and I wonder what this is:

constexpr struct X{ /* define X members and methods */ } Y{};

What i don't understand is the Y{}.

5
  • which part you dont understand? One could write a full article about that single line covering c-heritage up to latest c++ features. Commented Jun 8, 2018 at 9:40
  • What is something? What does it look like? Commented Jun 8, 2018 at 9:44
  • 3
    struct X{ /* something here */} defines a struct constexpr Y creates that struct that's a compile time constant called Y {}; initialises the values in the struct Commented Jun 8, 2018 at 9:44
  • 1
    @UKMonkey I'd make your comment an answer and link to another question that asks about list initialization. Maybe these questions help: stackoverflow.com/questions/41212130/… stackoverflow.com/questions/18222926/…. Commented Jun 8, 2018 at 9:47
  • ref. constexpr Commented Jun 8, 2018 at 9:48

1 Answer 1

2
constexpr struct X{ /* something here */} Y{};

is equal to

struct X{ /* something here */};

constexpr X Y{};

For constexpr, check this documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you! I missed the fact that you can initialize directly with {}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.