using hash_set in gcc3.3

Discussion in 'C++' started by Bart Blommerde, Oct 13, 2004.

  1. 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.
     
    Bart Blommerde, Oct 13, 2004
    #1
    1. Advertising

  2. Bart Blommerde

    Daniel Aarno Guest

    It's not just a namespace thing?

    /Daniel Aarno

    Bart Blommerde wrote:
    > 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.
    >
    >
     
    Daniel Aarno, Oct 13, 2004
    #2
    1. Advertising

  3. > 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.
     
    Bart Blommerde, Oct 13, 2004
    #3
  4. "Bart Blommerde" <> wrote in message
    news:416d17c2$0$42417$4all.nl...
    > > 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.
    >


    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
     
    John Harrison, Oct 13, 2004
    #4
  5. > 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.
     
    Bart Blommerde, Oct 13, 2004
    #5
  6. "Bart Blommerde" <> wrote in message
    news:416d3008$0$65124$4all.nl...
    > > 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. :(
    >


    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
     
    John Harrison, Oct 13, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Ying
    Replies:
    2
    Views:
    620
    James Ying
    Oct 28, 2003
  2. Philip Goisman
    Replies:
    5
    Views:
    505
    Jonathan Turkanis
    Jan 22, 2004
  3. John Black
    Replies:
    1
    Views:
    356
    Karthiik Kumar
    Aug 28, 2004
  4. zl2k
    Replies:
    2
    Views:
    577
  5. eric
    Replies:
    3
    Views:
    1,369
    Michael DOUBEZ
    Jul 12, 2011
Loading...

Share This Page