#include <iostream>
using namespace std;
struct base
{
virtual operator int()
{
return 1;
}
virtual ~base() {}
};
struct derive : public base
{
template <class _Ty>
operator _Ty()
{
return _Ty();
}
};
int main()
{
derive cd;
base & cb = cd;
int i = cd;
cout << i << "/n";
i = cd.derive::operator int();
cout << i << "/n";
i = cb;
cout << i << "/n";
double d = cd;
cout << d << "/n";
}
vc.net: 1 1 1 0
gcc: 1 0 1 1
icc: 0 0 1 0
派生类中的模板成员把基类的同名函数隐蔽了(即便是还未具现化)(保留)
using namespace std;
struct base
{
virtual operator int()
{
return 1;
}
virtual ~base() {}
};
struct derive : public base
{
template <class _Ty>
operator _Ty()
{
return _Ty();
}
};
int main()
{
derive cd;
base & cb = cd;
int i = cd;
cout << i << "/n";
i = cd.derive::operator int();
cout << i << "/n";
i = cb;
cout << i << "/n";
double d = cd;
cout << d << "/n";
}
vc.net: 1 1 1 0
gcc: 1 0 1 1
icc: 0 0 1 0
派生类中的模板成员把基类的同名函数隐蔽了(即便是还未具现化)(保留)