Search code examples
c++declare

Error : expected a ";"


Well this is a silly question but I have this error :

#include <unordered_set> 
std::unordered_set<std::string> ValidValues **{**"one", "two", "three"};

Error : expected a ";" appears at the first bracket. Exacty the same with a "set".

Restarted Visual Studio 2010 and the computer.


Solution

  • This works:

    #include <string>
    #include <unordered_set> 
    std::unordered_set<std::string> ValidValues {"one", "two", "three"};
    

    with GCC 4.4+, Clang 3.1+, and MSVS2013+.

    MSVS2010/2012 does not support the language feature called list initialization, wich is what you are doing.