How to get the number of elements in a struct?
Why not add the options as specified into an std::vector<string> options
and use the options.size()
method to check the correct number. Then convert them to the proper datatype.
A more robust way of doing this kind of thing would be to use Boost Program Options
This would require reflection, which C++ doesn't have.
So in your case, the code that parses the command line, checks for syntax errors, and sets the requested values in your struct will also have to check whether enough values are set.