C++实例,关于函数重载的一个问题!

来源:百度知道 编辑:UC知道 时间:2024/04/30 11:31:26
这是21天学能C++第十单,清单10.1的一个例子.

#include <iostream>

class rectangle
{
public:

rectangle(int width,int height);
~rectangle(){}

void drawshape() const;
void drawshape(int awidth,int aheight) const;

private:
int itswidth;
int itsheight;
};

rectangle::rectangle(int width,int height)
{
itswidth=width;
itsheight=height;
}

void rectangle::drawshape()const
{
drawshape(itswidth,itsheight);
}

void rectangle::drawshape(int width,int height) const
{
for(int i=0;i<height;i++)
{
for (int j=0;j<width;j++)
{
std::cout<<"*";
}
std::cout<<"\n";
}
}

int main()
{

rectangle therect(30,5);<

重载是C++的多态的一个体现,(多态的另外一个体现在虚函数),你说的是函数调用
重载是知相同的函数名在不同的地方出现不同的功能
通过函数的返回值以及参数的类型与个数来区分在什么时候调用哪一个同名函数

你说的是递归
重载是指函数名一样,而参数不同的情况