我不知道如何在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
unordered_set
hash<int> H;
这是相关的?我陷入了僵局,因为在经过数小时的谷歌咨询后,我确实无法弄清楚这一点。
答案 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
不是变量的好名称,因为它是标准类的名称。虽然它不应该成为编译错误的原因。