【ThinkingInC++】51、最好还是把定义放到外面,用inline来实现内联,而不是在类里面定义默认为内联
2014-09-16 19:05
507 查看
/** * 书本:【ThinkingInC++】 * 功能:当项目比较大的时候,最好还是把定义放到外面,用inline来实现内联,而不是在类里面定义默认为内联 * 时间:2014年9月16日19:06:25 * 作者:cutter_point */ class Rectangle { int width, height; public: Rectangle(int w=0, int h=0); int getWidth() const; void setWidth(int w); int getHeight() const; void setHeight(int h); }; inline Rectangle::Rectangle(int w, int h) : width(w), height(h) {} inline int Rectangle::getWidth() const {return width;} inline void Rectangle::setWidth(int w) {width=w;} inline int Rectangle::getHeight() const {return height;} inline void Rectangle::setHeight(int h) {height=h;} int main() { Rectangle r(19, 47); int iHeight=r.getHeight(); r.setHeight(r.getWidth()); r.setWidth(iHeight); return 0; }
相关文章推荐
- C++:对于class来说,什么函数可以在class里面定义,什么函数最好在class外面定义(我的理解)
- Thinking in c++ 2nd 习题解答之STL实现(一)
- C++定义一个类,如果成员变量没有说明是共有还是私有那默认的是哪一个?
- 【ThinkingInC++】38、选择重载还是默认参数
- C++定义一个类,如果成员变量没有说明是共有还是私有那默认的是哪一个?
- Thinking in C++ learning(3)-----隐藏实现
- 应当把 database的 validation 放到 database相关实现里面,而不是放到Ui
- C/C++语言之通过定义指针函数方式来实现在一个cpp文件里面获取另外一个cpp文件函数的返回值
- 头文件里面实现一个函数,在两个cpp中包含,则重复定义,如果加上inline则不会报错
- C++:为什么inline函数的定义要放在头文件里 + inline和宏定义的区别(暂未体会到)
- thinking in c++读书笔记--类的静态数据成员的定义的连接属性:外部连接属性
- Thinking in C++ learning(3)-----隐藏实现
- C/C++中默认参数在哪指定?函数声明还是定义?默认参数需放在右边
- Thinking in C++ 阅读笔记(第一章)
- Thinking in C++ (1-5)
- Thinking in C++ (1-2)
- C++中的property库的设计与实现过程(三)——将对象封装到property里面
- Thinking in C++ (1-6)
- 绝对经典 C++初学者必看的50个建议 (见过好几次了,还是放到我的日志中吧)
- Thinking in C++ 下载