Template specialization problem in C++

Discussion in 'General Computer Support' started by Onur Cobanoglu, Dec 13, 2009.

  1. Onur Cobanoglu

    Onur Cobanoglu

    Joined:
    Dec 13, 2009
    Messages:
    1
    Location:
    Pittsburgh, PA
    Hi,

    I have some user-defined classes, for which I have to define std::hash, which are nested in the scope of another user-defined class. So I have to specialize hash<> for those. The problem is that:

    1-) I cannot do the specialization before the outer class declaration, because if template parameters are classes then they should be fully declared previously (forward declaration does not work).
    2-) I cannot do the specialization after the outer class declaration, because I'm using the specialized hash<> classes within the scope of the outer class declaration and I'm getting a 'specialization after instantiation' error by the compiler.
    3-) I cannot do the specialization within the scope of the outer class, because hash<> is defined in namespace std and the compiler gives the error that template is specialized in non-namespace scope. When I try to enclose the specializations with

    Code:
    namespace std {}
    It gives me a weird error saying that "expected unqualified-id before ‘namespace’".

    So I'm stuck, and I don't know how to do these specializations. My full code is too long to include but here are the snippets relevant to the problem:


    Code:
    class BPCFGParser {
      public:
    
      ...
      ...
    
      class Edge {
        ...
        ...
      };
    
    
      class ActiveEquivClass {
        ...
        ...
      };
    
      class PassiveEquivClass {
        ...
        ...
      };
    
      struct EqActiveEquivClass {
        ...
        ...
      };
    
      struct EqPassiveEquivClass {
        ...
        ...
      };
    
    
    
      unordered_map<ActiveEquivClass, Edge *, hash<ActiveEquivClass>, EqActiveEquivClass> discovered_active_edges;
      unordered_map<PassiveEquivClass, Edge *, hash<PassiveEquivClass>, EqPassiveEquivClass> discovered_passive_edges;
    
    };
    

    In this code I'm trying to specialize std::hash<> for ActiveEquivClass and PassiveEquivClass. I'm working with g++ on Linux, with -std=gnu++0x option. Any help will be highly appreciated. Thanks.
     
    Onur Cobanoglu, Dec 13, 2009
    #1
    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. Thomas Kuborn
    Replies:
    2
    Views:
    517
    Thomas
    Jan 7, 2004
  2. Alex
    Replies:
    8
    Views:
    417
    Techie
    Aug 18, 2004
  3. Shawn Winters

    MCSE with specialization in security

    Shawn Winters, Sep 10, 2004, in forum: MCSE
    Replies:
    11
    Views:
    660
    The Poster Formerly Known as Kline Sphere
    Sep 12, 2004
  4. Pramod

    Security Specialization

    Pramod, Sep 29, 2004, in forum: MCSE
    Replies:
    5
    Views:
    618
    L.S.C. Jorge Garcia Fuentes
    Oct 5, 2004
  5. =?Utf-8?B?Y2hhbmFuZGxlcg==?=

    MCSE Specialization

    =?Utf-8?B?Y2hhbmFuZGxlcg==?=, Jan 4, 2005, in forum: MCSE
    Replies:
    8
    Views:
    519
    Ken Briscoe
    Jan 6, 2005
Loading...

Share This Page