Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:06:31+00:00 2026-05-30T22:06:31+00:00

I can compile this code that I got from an MSDN page : using

  • 0

I can compile this code that I got from an MSDN page:

using namespace std
typedef std::unordered_map<char, int> Mymap; 
Mymap c1;

c1.insert(Mymap::value_type('a', 1)); 
c1.insert(Mymap::value_type('b', 2)); 
c1.insert(Mymap::value_type('c', 3)); 

But when I change it to be:

using namespace std
typedef std::unordered_map<int, vector<int> > Mymap;
Mymap c1;

c1.insert(Mymap::value_type(1, vector<int> v (1,1))); 
c1.insert(Mymap::value_type(2, vector<int> v (1,2))); 
c1.insert(Mymap::value_type(3, vector<int> v (1,3))); 

I get the errors (the line numbers are obviously off for the snippet):

myfile.cpp:121:29: error: expected primary-expression before ‘(’ token
myfile.cpp:121:45: error: expected primary-expression before ‘v’
myfile.cpp:122:32: error: expected primary-expression before ‘(’ token
myfile.cpp:122:48: error: expected primary-expression before ‘v’
myfile.cpp:123:32: error: expected primary-expression before ‘(’ token
myfile.cpp:123:48: error: expected primary-expression before ‘v’

The hash map should be “int => list of ints”. With the list being initialized with one number.

What is the problem here? Do I need to use something other than value_type ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:06:32+00:00Added an answer on May 30, 2026 at 10:06 pm
    c1.insert(Mymap::value_type(1, vector<int> v (1,1))); 
                                               ^ // What's this 'v' doing there?
    

    What you are looking for is:

        c1.insert(Mymap::value_type(1, vector<int>(1,1)));
    

    That is, no v. vector<int> v(1, 1); declares a variable of type vector<int>, but you aren’t attempting to declare a variable, you’re attempting to construct a temporary object, for which no name is required (or allowed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Challenge: I have this code that fails to compile. Can you figure out what's
I've got a setup with Vim where I can compile my C/C++ code using
How can this code compile? The code below in the operator int CAN access
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
How can I get this to compile? The error is when I start using
Just for review, can someone quickly explain what prevents this from working (on compile):
I've got this code that works: def testTypeSpecialization: String = { class Foo[T] def
I've got this piece of code: using Posix; int fuseguifs_getattr(string path, Posix.Stat *stbuf) {
I have some neural net code written in c# that would benefit from using
I've got some code that I've been using successfully for some years to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.