函数的缺省参数实例
#include <iostream>using namespace std;
class A
{
public:
void set(int=30,int=15);
void count(bool=false);
private:
int w;
int h;
};
int main()
{
A a;
a.set();
a.count();
a.set(100,200);
a.count(true);
}
void A::set(int width,int height)
{
w=width;
h=height;
}
void A::count(bool val)
{
if(val==true)
{
cout<<"val的值为真时:"<<w*h<<endl;
}
else
{
cout<<"val的值为假时:"<<w*h/2<<endl;
}
}