using hash_set in gcc3.3

B

Bart Blommerde

Hi,

My question is about the STL extensions hash_set and hash_map, especially
the SGI versions of these templates. When defining a class like this :

#include <hash_set>
class MyClass : public hash_set<int>
{
// members here.
};

gcc2.95 would compile it without any errors or warnings. When using gcc3.3
however, compilation results in a syntax error (syntax error before '<').
Yes, I included ext/hash_set instead of hash_set, but it still doesn't seem
to recognize the hash_set as a defined template type.

Anyone got any idea what I'm doing wrong? I already tried full
specialization with hash_set<int, hash<int>, eqint, alloc<int> > but this
won't help either.

thanx for any help.
B.B.
 
B

Bart Blommerde

It's not just a namespace thing?

What do you mean exactly? I'm not used to using namespaces, but as far as I
know the only namespace I'm using is std.
 
J

John Harrison

Bart Blommerde said:
What do you mean exactly? I'm not used to using namespaces, but as far as I
know the only namespace I'm using is std.

But you aren't, that is the point.

#include <hash_set>
class MyClass : public std::hash_set<int>
{
};

An in any case you should not normally derive from standard containers.

#include <hash_set>
class MyClass
{
private:
std::hash_set<int> mySet;
};

is usually preferred. MyClass has a hash_set, it is not a kind of hash_set.
Therefore membership not inheritance is better.

john
 
B

Bart Blommerde

But you aren't, that is the point.
#include <hash_set>
class MyClass : public std::hash_set<int>
{
};

Well, I just saw in the SGI source files they use a different namespace for
these extensions. I just needed the following addition to my code :

using namespace __gnu_cxx;

This works, but is far from an ideal solution, since my code now doesn't
compile with gcc2.95. Some people just throw in new namespaces far too
easily. :(


B.B.
 
J

John Harrison

Bart Blommerde said:
Well, I just saw in the SGI source files they use a different namespace for
these extensions. I just needed the following addition to my code :

using namespace __gnu_cxx;

This works, but is far from an ideal solution, since my code now doesn't
compile with gcc2.95. Some people just throw in new namespaces far too
easily. :(

Apologies, I had completely forgotten that hash_set is not standard.
Although it's likely to become part of the standard at some point, until
then compilers are going to vary.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top