1

I got below sample code

// unordered_map::find
#include <iostream>
#include <string>
#include <unordered_map>

int main ()
{
  std::unordered_map<std::string,double> mymap = {
     {"mom",5.4},
     {"dad",6.1},
     {"bro",5.9} };

  std::string input;
  std::cout << "who? ";
  getline (std::cin,input);

  std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);

  if ( got == mymap.end() )
    std::cout << "not found";
  else
    std::cout << got->first << " is " << got->second;

  std::cout << std::endl;

  return 0;

When i try to compile it with VS 2010 on Windows 7 i get compile time error (though it look ok to me)

1>\testing.cpp(13): error C2552: 'mymap' : non-aggregates cannot be initialized with initializer list
1>          'std::tr1::unordered_map<_Kty,_Ty>' : Types with a base are not aggregate
1>          with
1>          [
1>              _Kty=std::string,
1>              _Ty=double
1>          ]
1>\testing.cpp(14): error C2078: too many initializers
1>\testing.cpp(15): fatal error C1903: unable to recover from previous error(s); stopping compilation

1 Answer 1

7

Your compiler (VC10) does not support uniform initialization. Your program compiles fine on a conforming compiler.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that as of now, no version of VC has the library initializer list constructors yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.