0

If I have a struct:

struct Vec2{
    double _x;
    double _y;
};

I can initialize that like this:

Vec2 foo = {13.0, 42.0};

But what if I have this struct?

struct Vec2{
    static const double INVALID;

    double _x;
    double _y;
};

Q. How do I initialize that struct?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 2
    Static members are shared by every instance. The code to initialize one instance of the struct does not change. – Neil Kirk Nov 18 '14 at 17:20
  • 1
    Initialise an instance exactly as you would without the static member - that doesn't change its aggregatosity. You'll also need a definition for the static member, `const double Vec2::INVALID = ;` in a source file. – Mike Seymour Nov 18 '14 at 17:47
  • [Neil Kirk](http://stackoverflow.com/users/2068573/neil-kirk) and [Mike Seymour](http://stackoverflow.com/users/204847/mike-seymour) thanks guys this is exactly what I wanted to know. I don't know if I can accept answers on a question that is marked as a duplicate, but if one of you wants to answer I'll try to accept. – Jonathan Mee Nov 18 '14 at 17:49

0 Answers0