Adventures in Functions
速度还行,两天看完一章,就是有细节没去扣。书上的大部分知识点和代码都看了,这个还是可以的。
今天继续来学习函数的高级特性,要涉及到以下的主题。
- 内联函数(inline function)
- 引用变量(reference variable)
- 通过引用传递函数参数
- 默认变量
- 函数重载
- 函数模板(template)
- 函数模板的specializations
C++内联函数
从机器语言的角度去解释函数的调用为什么会有开销,这一点值得深入研究以下,增加认识。
C++的内敛函数会用相应的代码去替代函数调用,这样的话不用跳到另一处去执行然后再跳回来,所以内敛函数要比一般的函数运行的稍快一些。
内敛函数不好的地方就是会占用内存,比如这个函数在10个地方被调用了,那么内联函数的这个代码会被存10份。
如何声明一个内联函数?
什么时候适合使用内联函数?
编译器一定认可你的内联函数么?
C++内联函数和C的宏定义(macro definition)
#include <iostream>
// 内联函数的定义
inline double square(double x) {return x * x; };
int main() {
using namespace std;
double a, b;
double c = 13.0;
a = square(5.0);
b = square(4.5 + 7.5);
cout << "a = " << ", b = " << b << "\n";
cout << "c = " << c;
// c++的意思是, 先去计算表达式, c = 13
// 把c = 3 拿去函数调用, 然后c再自增
cout << ", c squared = " << square(c++) << "\n";
cout << "Now c = " << c << "\n";
;
}
C++引用
https://www.cnblogs.com/tuhooo/p/5377406.html
默认参数
不太喜欢用默认参数,就这样吧
函数重载
这个概念我知道
函数模板
C++里面的泛型编程,抽取与类型无关的代码,达到通用的效果。
Adventures in Functions的更多相关文章
- c++中左值的含义
<<cpp primer plus 6th edition>>中的原文(Chapter 8 Adventures in Functions): What is an lvalu ...
- [ZZ] Adventures with Gamma-Correct Rendering
http://renderwonk.com/blog/index.php/archive/adventures-with-gamma-correct-rendering/ Adventures wit ...
- asp.net MVC helper 和自定义函数@functions小结
asp.net Razor 视图具有.cshtml后缀,可以轻松的实现c#代码和html标签的切换,大大提升了我们的开发效率.但是Razor语法还是有一些棉花糖值得我们了解一下,可以更加强劲的提升我们 ...
- 【跟着子迟品 underscore】Array Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- 【跟着子迟品 underscore】Object Functions 相关源码拾遗 & 小结
Why underscore 最近开始看 underscore.js 源码,并将 underscore.js 源码解读 放在了我的 2016 计划中. 阅读一些著名框架类库的源码,就好像和一个个大师对 ...
- ajax的使用:(ajaxReturn[ajax的返回方法]),(eval返回字符串);分页;第三方类(page.class.php)如何载入;自动加载函数库(functions);session如何防止跳过登录访问(构造函数说明)
一.ajax例子:ajaxReturn("ok","eval")->thinkphp中ajax的返回值的方法,返回参数为ok,返回类型为eval(字符串) ...
- QM模块包含主数据(Master data)和功能(functions)
QM模块包含主数据(Master data)和功能(functions) QM主数据 QM主数据 1 Material Master MM01/MM02/MM50待测 物料主数据 2 Sa ...
- jQuery String Functions
In today's post, I have put together all jQuery String Functions. Well, I should say that these are ...
- 2-4. Using auto with Functions
在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...
随机推荐
- Java Nashorn--Part 1
伴随 Java 8 的发布,Oracle 也一同发布了 Nashorn,它是在 Java 虚拟机上运行 Javascript 语言的一个引擎.Nashorn 的设计是为了替换最初的运行在 JVM 上的 ...
- Cross compiling coreutils and generate the manpages
When we cross compiling coreutils, there is an problem of generating man pages, because the source s ...
- 【转载并整理】mysql排序
由于oracle中有排序函数,可以使用over的语句方便排序,但是mysql中没有 这里碰到几个mysql的概念:用户变量.系统变量.if语句.函数GROUP_CONCAT 1. 可以使用定义变量(@ ...
- C#中 如何处理 JSON中的特殊字符
public static String StringToJson(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0 ...
- 腾讯云服务器 Centos6.5 安装 nginx1.12.0
今天买了腾讯云,不要问我为什么没有买阿里云... 入正题: 如果出现 CentOS ping: unknown host 的话,表示没有配置dns vim /etc/sysconfig/network ...
- SqlServer四种排序:ROW_NUMBER()/RANK()/DENSE_RANK()/ntile() over()
首先,我们创建一些测试数据. if OBJECT_ID('Tempdb.dbo.#Tmp') is not null drop table #Tmp create table #Tmp ( name ...
- mongodb学习比较(数据操作篇)
1. 批量插入: 以数组的方式一次插入多个文档可以在单次TCP请求中完成,避免了多次请求中的额外开销.就数据传输量而言,批量插入的数据中仅包含一份消息头,而多次单条插入则会在每次插入数据时封 ...
- 不忘初心,回归本质 .net core
static void Main(string[] args) { ; object j = i;//装箱 就是把值类型转换成引用类型 int k = (int)j;//拆箱 就是把引用类型转换成值类 ...
- [Windows Azure] Load Balancing Virtual Machines
Load Balancing Virtual Machines All virtual machines that you create in Windows Azure can automatica ...
- 每日英语:China's Bigger Innovation Problem
Last month's Third Plenum meeting of Chinese leaders seemed to signal Beijing's intention to experim ...