【发布时间】:2016-12-13 15:19:08
【问题描述】:
我从 C++ 开始,我发现了这个类的代码
class Box
{
public:
static int objectCount;
// Constructor definition
Box(double l=2.0, double b=2.0, double h=2.0)
{
cout <<"Constructor called." << endl;
length = l;
breadth = b;
height = h;
// Increase every time object is created
objectCount++;
}
double Volume()
{
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
但是,我不明白为什么在每个参数之后都有“=2.0” 构造函数...有人可以解释一下吗?
【问题讨论】:
-
如果您刚开始使用 C++,阅读初学者的 C++ 书籍可能更有效率。
-
这些是默认的函数参数,你应该搜索一下
-
juanchopanza -> 我就是这么做的……
标签: c++ class constructor