title: C++ Initializing array member with a length known by constructor at compile time
body: <p>I'm writing code for a display on an embedded device that displays screens, each with some amount of buttons. The amount of buttons differs between screens, but the amount is known at compile time.  </p>
  
  <p>Right now, here's a simplified version of how the classes are set up:</p>
  
  <pre><code>class Button;
  
  class Screen {
  private:
      Button *buttons;
      unsigned int buttonCount;
  public:
      Screen(Button *_buttons, unsigned int _buttonCount)
          : button(_buttons), buttonCount(_buttonCount) {}
  };
  </code></pre>
  
  <p>And here's an idea of how I've used them:</p>
  
  <pre><code>// For this example, Button has a constructor taking a string for
  // the button's label
  static Button buttonsForMainMenu[] = {
      Button("Do this"),
      Button("Do that"),
      Button("Exit")
  };
  
  Screen mainMenu (buttonsForMainMenu, 3);
  
  Screen *currentScreen = &amp;mainMenu;
  
  int main() {
      // ...
      while (1) {
          currentScreen-&gt;show();
          // handle buttons, etc.
      }
  }
  </code></pre>
  
  <p>I'd like to avoid having a separate array for buttons. Ideally, something like this:</p>
  
  <pre><code>Screen mainMenu ({
      Button("Do this"),
      Button("Do that"),
      Button("Exit")
  });
  </code></pre>
  
  <p>This code is for an embedded system that hasn't needed dynamic memory allocation, so I'd like to keep avoiding that. <code>std::array</code> needs the array size at its declaration within the class declaration, but the Screens will have different amounts of Buttons. The Screen class I don't believe can be templated because of <code>currentScreen</code>.</p>
  
  <p>Is there a way for a class to have an array where the array size is found at its declaration/at compile-time?</p>