C++中的hash_set是如何工作的
How does hash_set in C++ work?
我不知道如何在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
- 我不知道"在类范围内为非成员使用声明"是什么意思
- 当我基本上遵循SGI在他们网站上的相同示例时,为什么编译器会抱怨"在'<'标记之前应为';'"
- 我正在使用gcc 3.4.6,因此无法使用
unordered_set
- 我看了一个简单的C++hash_set示例,但我不明白他们为什么使用
hash<int> H;
,这有关系吗
我陷入了僵局,因为在咨询谷歌数小时后,我真的无法弄清楚这一点。
我认为您应该将map
声明为
// answering your other question, most likely it doesn't have to be a pointer.
__gnu_cxx::hash_set<Card::Value> map;
(根据hash_set来源)
此外,map
不是一个好的变量名称,因为它是一个标准类的名称。尽管这不应该是编译错误的原因。
相关文章:
- QSqlquery prepare()和bindvalue()不工作
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- 有人能解释一下为什么下界是这样工作的吗C++的
- ExtractIconEx:可以工作,但偶尔会崩溃
- C++中的memset函数工作不正常
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 当 int 方法工作正常时,void 方法有何不同,或者为什么我不能调用 void 方法?
- sdl软件渲染器不工作,工作在硬件加速的一个