0

に渡されるカスタム C++ 比較関数を実装しようとしていstd::mapます。mapAPIの指示に従って、以下を実装しました。

 35 typedef std::pair<uint64_t, KeyHash> TabletKey;
 36 
 37 class CmpTabletKey {
 38     public:
 39         bool operator()(const TabletKey& key1, const TabletKey& key2) const {
 40             if (!(key1.first < key2.first)) {
 41                 return false;
 42             }
 43             if (!(key2.first < key1.first)) {
 44                 return false;
 45             }
 46 
 47             return true;
 48         }
 49 };

mapがプロパティであるクラス内には、次のものがあります。

 55 class ObjectFinder {
 56   public:
 57     class TableConfigFetcher; // forward declaration, see full declaration below
 58     class CmpTabletKey;
        // .. more code here
      private:
 97     std::map<TabletKey, ProtoBuf::Tablets::Tablet, CmpTabletKey> tableMap;
     }

そして、次のエラーが発生します。

/home/ribeiro.phillipe/ramcloud/src/ObjectFinder.h:97:   instantiated from here
/usr/lib/gcc/x86_64-redhatlinux/4.4.6/../../../../include/c++/4.4.6/bits/stl_tree.h:453: 
error: incomplete type ‘RAMCloud::ObjectFinder::CmpTabletKey’ not allowed
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/map:60,

なぜそれが起こっているのかわかりません。また、私はstd::less実装をあまり使用することはありません

4

2 に答える 2

1

通常、テンプレート パラメーターとして標準ライブラリ テンプレートに渡される型は、テンプレートのインスタンス化時に完全に定義する必要があります。(例外はスマート ポインター テンプレートです)
これは のコンパレーターにも適用されるstd::mapため、前方宣言では十分ではありませんCmpTabletKey

std::map<TabletKey, ProtoBuf::Tablets::Tablet, CmpTabletKey> tableMap;
                                             //^^^------- needs full definition
于 2013-07-30T09:47:35.267 に答える