C ++中的hash_set如何工作?

时间:2014-11-12 21:54:27

标签: c++ hashset gcc3

我不知道如何在C ++中使用hash_set。我对这种语言非常陌生,所以我不明白如何做很多事情。如何使用SGI hash_set扩展,以便编译器最终编译而不会出错?这是我的头文件:

#ifndef _GAME1_H
#define _GAME1_H

#include "card.h"
#include "deck.h"
#include <ext/hash_set>

const unsigned int TRIALS = 10;

class Game1 {

private:
    // Card::Value is defined in card.h as a public enum:
    // enum Value { NullCard, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King };
    std::hash_set<Card::Value> *map; // does this really need to be a pointer?

public:
    Game1();
    bool isPair();
    bool isFlush();
    void returnToDeck();
};

#endif

当我尝试编译时,我得到:

In file included from game1.cpp:9:
game1.h:13: error: using-declaration for non-member at class scope
game1.h:13: error: expected `;' before '<' token
make: *** [game1.o] Error 1
  1. 我不知道&#34;在课堂范围内对非会员使用声明&#34;装置中。
  2. 为什么编译器抱怨&#34;期望`;&#39;之前&#39;&lt;&#39;令牌&#34;当我基本上遵循与SGI has on their site相同的例子时?
  3. 我正在使用gcc 3.4.6,因此我无法使用unordered_set
  4. 我看过simple C++ hash_set example,但我不明白为什么他们使用hash<int> H;这是相关的?
  5. 我陷入了僵局,因为在经过数小时的谷歌咨询后,我确实无法弄清楚这一点。

1 个答案:

答案 0 :(得分:0)

我相信您应该将map声明为

// answering your other question, most likely it doesn't have to be a pointer.
__gnu_cxx::hash_set<Card::Value> map;

(根据hash_set source

此外,map不是变量的好名称,因为它是标准类的名称。虽然它不应该成为编译错误的原因。