Topic: Overloading + templates = UBHosed


Author: scotty@cinenet.net (J Scott Peter XXXIII i/iii)
Date: 1996/05/07
Raw View
MS VC++ 4.1 has seemingly erroneous behavior in the following two cases.
What do the current and upcoming standards say about this?

template<class T> class Base
{
    T x;
};

template<class T> class Derived: public Base<T>
{
    T y;
};

template<class T> void func(Base<T>, double);
template<class T> void func(Derived<T>, double);

void test()
{
    Base<int> base;
    Derived<int> derived;

    func(base, 3.0);       // OK.
    func(derived, 3.0);    // Chokes: "Ambiguous call to overloaded function".
    func(base, 3);         // Chokes: "None of the 2 overloads can convert
                           // parameter 2 from type 'const int'"
}

Isn't this behavior obviously wrong?  Interestingly, if you reverse the order
of func's arguments in both the declarations and calls, the second error goes
away!

J Scott Peter XXXIII i/iii    // Wrong thinking is punishable.
Venice, CA, USA              // Right thinking will be as quickly rewarded.
                            // You will find it an effective combination.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]