template specialization hides other specializations-msvc6

Discussion in 'C++' started by Tom Richardson, Dec 19, 2003.

  1. The following code gives the output "1.21.21.2" with msvc6,
    while it gives "1.2T34" with g++.

    What's up with this?

    Regards, Tom
    ----
    #include <iostream>
    using namespace std;

    template<class T>
    void plum() { cout << "T"; }

    template<>
    void plum<double>() { cout << 1.2; }

    template<>
    void plum<int>() { cout << 34; }

    int main()
    {
    plum<double>();
    plum<bool>();
    plum<int>();
    return 0;
    }
    Tom Richardson, Dec 19, 2003
    #1
    1. Advertising

  2. "Tom Richardson" <> wrote...
    > The following code gives the output "1.21.21.2" with msvc6,
    > while it gives "1.2T34" with g++.
    >
    > What's up with this?


    VC++ v6 cannot handle template specialisations. It always calls
    the first one it encounters. A known bug.

    >
    > Regards, Tom
    > ----
    > #include <iostream>
    > using namespace std;
    >
    > template<class T>
    > void plum() { cout << "T"; }
    >
    > template<>
    > void plum<double>() { cout << 1.2; }
    >
    > template<>
    > void plum<int>() { cout << 34; }
    >
    > int main()
    > {
    > plum<double>();
    > plum<bool>();
    > plum<int>();
    > return 0;
    > }
    Victor Bazarov, Dec 19, 2003
    #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. Tseng, Ling-hua
    Replies:
    0
    Views:
    427
    Tseng, Ling-hua
    Dec 8, 2003
  2. Thomas Matthews

    Order of template specializations

    Thomas Matthews, Feb 26, 2004, in forum: C++
    Replies:
    0
    Views:
    322
    Thomas Matthews
    Feb 26, 2004
  3. Imre
    Replies:
    1
    Views:
    285
    Chris Jefferson
    Feb 21, 2005
  4. christian
    Replies:
    5
    Views:
    325
    christian
    Jan 14, 2006
  5. Joseph Turian
    Replies:
    2
    Views:
    451
Loading...

Share This Page