解释一下c++中重载和重定义(redefine)的区别,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/24 05:30:51
最好能给出代码来说明。

#include <iostream>
using namespace std;

struct foo
{
void act() {cout << "foo\n";}
virtual ~foo() {}
};

struct bar : public foo
{
void act() {cout << "bar\n";}
void act(int) {cout << "foobar\n";}
};

int main()
{
foo f;
f.act();
bar b;
b.act(); // redefine or overwrite
b.act(123); // overload
}

#include <iostream.h>
int& IntMax(int const&a,int const&b)
{
cout << "调用int版本:";
return a > b ? a : b;
}
long& LongMax(long const&a, long const&b)
{
cout << "调用long版本:";
return a > b ? a : b;
}
char& CharMax(char const&a, char const&b)
{
cout << "调用char版本:";
return a > b ? a : b;
}

class Base
{
public:
virtu