函数的隐藏和覆盖在C++中区别是非常之大#include <iostream>
using namespace std;
class a
{
public:
void hello()
{
cout << "基类a的hello函数" << endl;
}
void hello(int i)
{
cout << "a.hello(i): " << i << endl;
cout << "基类a的带一个参数的hello函数" << endl;
}
};
// 函数的隐藏和覆盖在C++中区别是非常之大的.
class b : public a
{
public:
void hello() const
{
cout << "子类b的hello函数" << endl;
}
// void hello(int i) const
// {
// cout << "b.hello(i): " << i << endl;
// cout << "子类b的带一个参数的hello函数" << endl;
// }
};
int main()
{
b b;
b.hello();
b.hello(2);
system("pause");
return 0;
}
#include <iostream>
using namespace std;
class a
{
public:
void hello()
{
cout << "基类a的hello函数" << endl;
}
void hello(int i)
{
cout << "a.hello(i): " << i << endl;
cout << "基类a的带一个参数的hello函数" << endl;
}
};
// 函数的隐藏和覆盖在C++中区别是非常之大的.
class b : public a
{
public:
void hello() const
{
cout << "子类b的hello函数" << endl;
}
// void hello(int i) const
// {
// cout << "b.hello(i): " << i << endl;
// cout << "子类b的带一个参数的hello函数" << endl;
// }
};
int main()
{
b b;
b.hello();
b.hello(2);
system("pause");
return 0;
}