Bobby Digital
Bobby Digital

Reputation: 33

std::tr1::unordered_map insert error

I'm unable to use the insert function for a std::tr1::unordered_map, I keep receiving the following error when attempting to build:

/usr/include/c++/4.2.1/tr1/hashtable:855:14: error: cannot initialize return object of type '_Node *' (aka '_Hash_node<std::pair<const unsigned long long, Order>, false> *') with an rvalue of type 'bool'
      return false;
         ^~~~~

My condensed code is as follows:

#include <tr1/unordered_map>
#include "handler.h"
#include "endian_tools.h"

using namespace std::tr1;
using namespace std;

unordered_map<uint64_t, Order> book_by_id;

uint64_t ref_num = be64toh(msg);
Order order(ref_num);

book_by_id.insert(make_pair<uint64_t,Order>(ref_num, order));

I thought maybe it had to do with the fact that I was using a long long as the key but even after changing that to an int I get the same error. Any thoughts? I haven't been able to find anyone else with this error anywhere online.

Upvotes: 2

Views: 1015

Answers (1)

Bobby Digital
Bobby Digital

Reputation: 33

I think the issue was with my gcc version and its lack of support for C++11 (Mac OSX uses an old gcc version by default which is how I ended up in this situation). I upgraded my gcc to 4.8 with macports, set it to default, and created a new project with the CrossGCC compiler per these instructions: use c++11 on mac os x mountain lion with eclipse (Juno or Kepler). I removed the tr1 and am now only using #include <unordered_map>. Now I have no issue using the insert method.

Thanks all for the suggestions.

Upvotes: 1

Related Questions