Could anyone tell me about template partial specialization..?

Discussion in 'C++' started by BekTek, Nov 25, 2004.

  1. BekTek

    BekTek Guest

    I'm still confused about the template partial specialization which is used
    in many libraries..
    due to lack of introduction for beginner..

    Could you tell me about that in short?
    Thanks in advance..
     
    BekTek, Nov 25, 2004
    #1
    1. Advertising

  2. BekTek

    Sharad Kala Guest

    "BekTek" <> wrote in message

    > I'm still confused about the template partial specialization which is used
    > in many libraries..
    > due to lack of introduction for beginner..


    Consider this code -

    #include <iostream>
    using namespace std;

    template<class T1, class T2>
    struct A
    {
    void foo()
    {
    cout << "Primary template\n";
    }
    };

    template<class T1>
    struct A<T1, int>
    {
    void foo()
    {
    cout << "Partial specialization\n";
    }
    };

    int main()
    {
    A<float, double> a1;
    a1.foo(); // Calls primary template

    A<float, int> a2;
    a2.foo(); // Calls partial specialization
    }

    Analyze the code, whenever the second template parameter is an int the
    partial specialization gets chosen.

    Sharad
     
    Sharad Kala, Nov 25, 2004
    #2
    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. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,061
    tom_usenet
    Jun 25, 2003
  2. Joseph Turian
    Replies:
    2
    Views:
    494
  3. toton
    Replies:
    1
    Views:
    632
  4. vj
    Replies:
    1
    Views:
    505
  5. Hizo
    Replies:
    17
    Views:
    715
    itaj sherman
    Mar 7, 2011
Loading...

Share This Page