"in-class member initializer fails with vs 2013" Code Answer

19
  • The example that you showed is perfectly valid C++, however it doesn't work for VC++2013.

  • This is a known VC++2013 bug reported since 31/10/2013 and its status is still active.

  • However, you can surmount it by doing a work-around. As @ildjarn suggested, by simply putting an extra pair of curly braces you force initializer_list<> constructor of the std::vector to be evoked instead of its fill constructor, like the example below:


   #include <string>
   #include <vector>
   #include <iostream>

   struct Settings {
     std::vector<std::string> allowable = {{"-t", "--type", "-v", "--verbosity"}};
   };

   int main() {
     Settings s;
     for (auto i : s.allowable) std::cout << i << " ";
     std::cout << std::endl;
   }
By Graffl on April 3 2022

Answers related to “in-class member initializer fails with vs 2013”

Only authorized users can answer the Search term. Please sign in first, or register a free account.