I
Imre
Why is the function template a better match for the call in the
following code?
And how could I write a version of F() that should be called if the
argument is a pointer to a type that is derived from B, while the
template version should be called for all other argument types?
#include <iostream>
using namespace std;
struct B {};
struct D: public B {};
template <typename T>
int F(T &t) { return 1; }
int F(B *pb) { return 2; }
int main(int argc, char* argv[])
{
D *pd = new D;
int i = F(pd);
cout << i << '\n'; // writes 1 (VC++ 7.1), I'd like to get 2
return 0;
}
Thanks.
Imre
following code?
And how could I write a version of F() that should be called if the
argument is a pointer to a type that is derived from B, while the
template version should be called for all other argument types?
#include <iostream>
using namespace std;
struct B {};
struct D: public B {};
template <typename T>
int F(T &t) { return 1; }
int F(B *pb) { return 2; }
int main(int argc, char* argv[])
{
D *pd = new D;
int i = F(pd);
cout << i << '\n'; // writes 1 (VC++ 7.1), I'd like to get 2
return 0;
}
Thanks.
Imre