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

  • SEARCH
  • Home
  • 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 4621574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:43:15+00:00 2026-05-22T02:43:15+00:00

I am trying to insert into an unordered_map with a std::set value declared as

  • 0

I am trying to insert into an unordered_map with a std::set value declared as such:

class Database {
...
private:
    struct CountryRCID {
        int RCID;
        int Vote;
    };
    struct comp {
        bool operator() (const CountryRCID& left, const CountryRCID& right) const {
            return left.RCID < right.RCID;
        }
    };
    std::unordered_map<const char*, std::set<CountryRCID, comp> > CNTVotes;
};

In the Database constructor I am reading data in from a file and attempting to insert into the unordered_map

Database() {
    char CNT[3];
    CountryRCID RCIDVote;
    ... Insert data into CNT and RCIDVote ...
    CNTVotes.insert(std::make_pair(CNT, RCIDVote));
}

And I have attempted compiling the code with both:

g++ main.cpp -std=gnu++0x

and

g++ main.cpp -std=c++0x

But am receiving the error:

In file included from /usr/include/c++/4.4/bits/stl_algobase.h:66,
                 from /usr/include/c++/4.4/bits/char_traits.h:41,
                 from /usr/include/c++/4.4/ios:41,
                 from /usr/include/c++/4.4/istream:40,
                 from /usr/include/c++/4.4/fstream:40,
                 from db.h:1,
                 from main.cpp:1:
/usr/include/c++/4.4/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = char*, _U2 = Database::CountryRCID, _T1 = const char* const, _T2 = std::set<Database::CountryRCID, Database::comp, std::allocator<Database::CountryRCID> >]’:
db.h:50:   instantiated from here
/usr/include/c++/4.4/bits/stl_pair.h:107: error: no matching function for call to ‘std::set<Database::CountryRCID, Database::comp, std::allocator<Database::CountryRCID> >::set(Database::CountryRCID)’
/usr/include/c++/4.4/bits/stl_set.h:212: note: candidates are: std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_CharT>, const _Compare&, const _Alloc&) [with _Key = Database::CountryRCID, _Compare = Database::comp, _Alloc = std::allocator<Database::CountryRCID>]
/usr/include/c++/4.4/bits/stl_set.h:199: note:                 std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&) [with _Key = Database::CountryRCID, _Compare = Database::comp, _Alloc = std::allocator<Database::CountryRCID>]
/usr/include/c++/4.4/bits/stl_set.h:188: note:                 std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&) [with _Key = Database::CountryRCID, _Compare = Database::comp, _Alloc = std::allocator<Database::CountryRCID>]
/usr/include/c++/4.4/bits/stl_set.h:145: note:                 std::set<_Key, _Compare, _Alloc>::set(const _Compare&, const _Alloc&) [with _Key = Database::CountryRCID, _Compare = Database::comp, _Alloc = std::allocator<Database::CountryRCID>]
/usr/include/c++/4.4/bits/stl_set.h:136: note:                 std::set<_Key, _Compare, _Alloc>::set() [with _Key = Database::CountryRCID, _Compare = Database::comp, _Alloc = std::allocator<Database::CountryRCID>]

I have also tried different insert methods:

CNTVotes[CNT] = RCIDVote;

and

std::pair <const char*, CountryRCID> test (CNT, RCIDVote);
CNTVotes.insert(test);

which just results in similar errors

I would very much appreciate it if anyone could help me understand why it is not working and what I could do to make this work.

Thank you.

  • 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-22T02:43:16+00:00Added an answer on May 22, 2026 at 2:43 am

    CountryRCID is a type struct, it is not a std::set … you would first need to construct a std::set of type std::set<CountryRCID> and use that in your arguments to makePair() in order to match the template arguments for your unordered_map.

    I also think the struct comp functor is redundant … just define operator<() and operator==() for your CountryRCID struct.

    If you do that, and change the declaration of CNTVotes to (BTW, note that I’m borrowing Neil’s suggestion to use std::string rather than a const char* as the key-value … I think that’s a very good idea)

    std::unordered_map<std::string, std::set<CountryRCID> > CNTVotes;
    

    then you can do the following:

    CountryRCID RCIDVote;
    //... Insert data into CNT and RCIDVote ...
    std::string CNTString(CNT);
    std::set<CountryRCID> RCIDVoteSet;  // <== make a std::set of type set<CountryRCID>
    RCIDVoteSet.insert(RCIDVote);
    CNTVotes.insert(std::make_pair(CNTString, RCIDVoteSet));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert data into my SQlite3 database (this works via the command
Trying to insert into a mongodb database from scala. the below codes dont create
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and
I'm trying to insert some data into a local MySQL database by using MySQL
I'm trying to insert a System.DateTime into an Access database using a parameterized OleDbCommand
I'm trying to insert the current date from a php form into a database.
im trying to insert data into a particular row in the database, but i
I'm trying to insert text into my SQLite database, but for some reason it
I'm trying to insert information into multiple tables within a database, i have managed
I'm trying to insert information from a form into a database table and then

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.