Team LiB
Previous Section Next Section

Chapter 7. Functions

第七章 函数

CONTENTS

Section 7.1 Defining a Function

226

Section 7.2 Argument Passing

229

Section 7.3 The return Statement

245

Section 7.4 Function Declarations

251

Section 7.5 Local Objects

254

Section 7.6 Inline Functions

256

Section 7.7 Class Member Functions

258

Section 7.8 Overloaded Functions

265

Section 7.9 Pointers to Functions

276

Chapter Summary

280

Defined Terms

280


This chapter describes how to define and declare functions. We'll cover how arguments are passed to and values are returned from a function. We'll then look at three special kinds of functions: inline functions, class member functions, and overloaded functions. The chapter closes with a more advanced topic: function pointers.

本章将介绍函数的定义和声明。其中讨论了如何给函数传递参数以及如何从函数返回值。然后具体分析三类特殊的函数:内联(inline)函数、类成员函数和重载函数。最后以一个更高级的话题“函数指针”来结束全章。

A function can be thought of as a programmer-defined operation. Like the built-in operators, each function performs some computation and (usually) yields a result. Unlike the operators, functions have names and may take an unlimited number of operands. Like operators, functions can be overloaded, meaning that the same name may refer to multiple different functions.

函数可以看作程序员定义的操作。与内置操作符相同的是,每个函数都会实现一系列的计算,然后(大多数时候)生成一个计算结果。但与操作符不同的是,函数有自己的函数名,而且操作数没有数量限制。与操作符一样,函数可以重载,这意味着同样的函数名可以对应多个不同的函数。

Team LiB
Previous Section Next Section