📄 rectangle2.cpp
字号:
//: C09:Rectangle2.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Accessors & mutators with "get" and "set"
class Rectangle {
int width, height;
public:
Rectangle(int w = 0, int h = 0): width(w), height(h)
{}
int getWidth() const //access functions
{ return width; }
void setWidth(int w)
{ width = w; }
int getHeight() const
{ return height; }
void setHeight(int h)
{ height = h; }
};
int main() {
Rectangle r(19, 47);
// Change width & height:
r.setHeight(2 * r.getWidth());
r.setWidth(2 * r.getHeight());
} ///:~
//access is remarkably efficient. Consider the getWidth(), for example. Without inlines,
//the code generated for the call to getWidth() would be larger than the code created by the
//inline, and the execution time would certainly be longer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -