注意默认参数的定义
如果一个类中的函数有默认参数,则只能在这个函数声明的时候写默认参数,在函数定义的时候不能写默认参数。
//"Rectangle.cpp"
#include <iostream>
#include "Rectangle.h"
using namespace std;
Rectangle::Rectangle(coordinate lowerLeft , coordinate upperRight )//这里不写默认参数
{
this->lowerLeftPoint = {min(lowerLeft.x, upperRight.x), min(lowerLeft.y, upperRight.y)};
this->upperRightPoint = {max(lowerLeft.x, upperRight.x), max(lowerLeft.y, upperRight.y)};
cout << "\tconstructor is called !" << endl;
}
//"Rectangle.h"
class Rectangle
{
public:
Rectangle(coordinate lowerLeft = {0, 0}, coordinate upperRight = {1, 1});//这里写默认参数
}
同一个类中注意函数名不能和变量名重复
class Circle
{
private:
double area;//写成double Area编译不能通过。
public:
void Area();
};

1649

被折叠的 条评论
为什么被折叠?



