/*
如果派生类不止派生了与基类虚函数相同类型的参数,
还重载了该函数的情况验证。
结论:子类调用时可以通过参数类型来判断调用那个成员函数,相当于普通函数的重载
父类指针实现多态还是可以的,只是只能调用那个参数类型与父类虚函数参数类型相同的函数
*/
#include <iostream>
using namespace std;
class CBase
{
public:
virtual void Print(int a)
{
cout << "This is Base virtual fun!" << endl;
}
};
class Cdeprived : public CBase
{
public:
void Print (int a)
{
cout << "This is deprived class virtual fun!"<< endl;
}
void Print (const string &b)
{
cout << "no virtual" << b << endl;
}
};
int main()
{
CBase *base = new Cdeprived();
base->Print(123);
Cdeprived CBase ;
CBase.Print("123");
CBase.Print(123);
return 0;
}
如果派生类不止派生了与基类虚函数相同类型的参数,
还重载了该函数的情况验证。
结论:子类调用时可以通过参数类型来判断调用那个成员函数,相当于普通函数的重载
父类指针实现多态还是可以的,只是只能调用那个参数类型与父类虚函数参数类型相同的函数
*/
#include <iostream>
using namespace std;
class CBase
{
public:
virtual void Print(int a)
{
cout << "This is Base virtual fun!" << endl;
}
};
class Cdeprived : public CBase
{
public:
void Print (int a)
{
cout << "This is deprived class virtual fun!"<< endl;
}
void Print (const string &b)
{
cout << "no virtual" << b << endl;
}
};
int main()
{
CBase *base = new Cdeprived();
base->Print(123);
Cdeprived CBase ;
CBase.Print("123");
CBase.Print(123);
return 0;
}