Initialization of a templated data member cryptic error

我是研究僧i 提交于 2019-12-25 09:17:37

问题


This is my tmp.hpp:

#include <cstdlib>
#include <utility>
#include <unordered_map>

using namespace std;

struct int_int_hasher {
  size_t operator()(pair<int, int> const& p) const {
    return static_cast<size_t>(p.first) << 32 | p.second;
  }
};

template<class T, class H>
class BiBag {
  unordered_map<T, uint, H> t_to_id_;
};

And simple tmp.cpp:

#include "tmp.hpp"

class tmp {
  BiBag<pair<int, int>, int_int_hasher> tt =
    BiBag<std::pair<int, int>, int_int_hasher>();
};

The error message is beyond my understanding:

g++ -std=c++11 -O2 tmp.cpp -lm -o tmp
tmp.cpp:6:32: error: expected ‘;’ at end of member declaration
     BiBag<std::pair<int, int>, int_int_hasher>();
                                ^
tmp.cpp:6:32: error: declaration of ‘BiBag<std::pair<int, int>, int_int_hasher> tmp::int_int_hasher’ [-fpermissive]
In file included from tmp.cpp:2:0:
tmp.hpp:7:8: error: changes meaning of ‘int_int_hasher’ from ‘struct int_int_hasher’ [-fpermissive]
 struct int_int_hasher {
        ^
tmp.cpp:6:46: error: expected unqualified-id before ‘>’ token
     BiBag<std::pair<int, int>, int_int_hasher>();
                                              ^
tmp.cpp:6:16: error: wrong number of template arguments (1, should be 2)
     BiBag<std::pair<int, int>, int_int_hasher>();
                ^

If I remove the hasher from the picture and replace the map with a simple <int,int> map I get no error.

Thank you.

来源:https://stackoverflow.com/questions/41435064/initialization-of-a-templated-data-member-cryptic-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!