title: Can we use dynamic array data() as a longopts parameter in getopt_long function?
body: <p>I am trying to create an argument parsing class on C++ that will be using <code>getopt_long</code> function.
  So basically I want the <code>longopts</code> argument can be created dynamically.</p>
  <p>This code, that using static array for <code>longopts</code> argument will work:</p>
  <pre><code>int main(int argc, char **argv) {
    while (true) {
      static struct option long_options_static[] = {
        {&quot;a&quot;, required_argument, 0, 'a'},
        {&quot;b&quot;, required_argument, 0, 'b'},
      };
      int option_index = 0;
      char c = getopt_long(argc, argv, &quot;&quot;, long_options_static, &amp;option_index);
    }
    return 0;
  }
  </code></pre>
  <p>But this, that using <code>std::vector</code> will compile but not work as expected:</p>
  <pre><code>int main(int argc, char **argv) {
    while (true) {
      std::vector&lt;struct option&gt; long_options_vect(2);
      long_options_vec[0] = {&quot;a&quot;, required_argument, 0, 'a'};
      long_options_vec[1] = {&quot;b&quot;, required_argument, 0, 'b'};
      int option_index = 0;
      char c = getopt_long(argc, argv, &quot;&quot;, long_options_vect.data(), &amp;option_index);
    }
    return 0;
  }
  </code></pre>
  <p>From the <code>getopt_long</code> <a href="https://linux.die.net/man/3/getopt_long" rel="nofollow noreferrer">manual</a>, it only stated that</p>
  <blockquote>
  <p>longopts is a pointer to the first element of an array of struct option...</p>
  </blockquote>
  <p>So in theory, using any kind of containers such as std::vector or std::array and then passing the storage's pointer is possible right?
  But I get <code>unrecognized option</code> error, am I missing something?</p>