How does hash_set in C++ work?

1.4k views Asked by At

I don't know how to use hash_set in C++. I'm incredibly new to this language so I don't understand how to do a lot of things. How do I use the SGI hash_set extension so the compiler finally compiles without error? Here is my header file:

#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

When I try to compile I get:

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. I don't know what "using-declaration for non-member at class scope" means.
  2. Why is the compiler complaining that "expected `;' before '<' token" when I'm basically following the same example as SGI has on their site?
  3. I am using gcc 3.4.6 so I cannot use unordered_set
  4. I have looked at simple C++ hash_set example but I don't understand why they're using hash<int> H; is this relevant?

I'm at a stalemate since I literally cannot figure this out after hours of consulting google.

1

There are 1 answers

0
Anton Savin On

I believe you should declare map as

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

(According to the hash_set source)

Also, map is not a good name for a variable since it's the name of a standard class. Though it shouldn't be a cause for compilation errors here.