how to Specializations of function Templates or Overloading Function templates with Templates ?

Discussion in 'C++' started by recover, Jul 25, 2006.

  1. recover

    recover Guest

    #include <stdio.h>

    template<class T>
    class TpHello
    {
    public:
    int GetHash(){return 0;}
    protected:
    private:
    T a;
    };

    template<class T>
    int HashKey(T key)
    {
    return (int)key;
    }

    //Specializations of function Templates or Overloading Function templates
    template<class T>
    int HashKey(TpHello<T> key)
    {
    return key.GetHash();
    }

    int main()
    {
    TpHello<int> tpInt;
    HashKey(tpInt);
    return 0;
    }


    compile error in VC6
    --------------------Configuration: template - Win32
    Debug--------------------
    Compiling...
    template.cpp
    E:\work\hellotest\template.cpp(52) : error C2667: 'HashKey' : none of 2
    overload have a best conversion
    E:\work\hellotest\template.cpp(52) : error C2668: 'HashKey' : ambiguous call
    to overloaded function
    Error executing cl.exe.

    template.exe - 2 error(s), 0 warning(s)

    --
    = = = = = = = = = = = = = = = = = = = = = =

    ¡¡¡¡¡¡¡¡¡¡¡¡¡¡
    zhang
    ----------------------------
    Co.: beijing lingtu
    Ad.: beijing zpart
    ZIP£º 100094
    Mail£º
    MSN:
    Com.£º http://www.lingtu.com/
    http://www.51ditu.com/
    --------------------------
    recover, Jul 25, 2006
    #1
    1. Advertising

  2. recover wrote:
    > [..valid code redacted..]
    >
    >
    > compile error in VC6
    > [..]


    Please, PLEASE, throw that compiler away. Get yourself something
    decent. Luckily, there are several free ones available.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jul 25, 2006
    #2
    1. Advertising

  3. recover

    recover Guest

    Thanks.


    >
    > Please, PLEASE, throw that compiler away. Get yourself something
    > decent. Luckily, there are several free ones available.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask
    >
    >
    recover, Jul 25, 2006
    #3
    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. Tseng, Ling-hua
    Replies:
    0
    Views:
    430
    Tseng, Ling-hua
    Dec 8, 2003
  2. Tom Richardson
    Replies:
    1
    Views:
    316
    Victor Bazarov
    Dec 19, 2003
  3. Thomas Matthews

    Order of template specializations

    Thomas Matthews, Feb 26, 2004, in forum: C++
    Replies:
    0
    Views:
    324
    Thomas Matthews
    Feb 26, 2004
  4. CoolPint
    Replies:
    4
    Views:
    346
    CoolPint
    Sep 18, 2004
  5. christopher diggins
    Replies:
    4
    Views:
    392
    christopher diggins
    Dec 21, 2004
Loading...

Share This Page