参数传递
const形参和实参
不能把const对象,字面值,需要类型转换的对象传递给普通的引用形参
数组形参
数组不允许拷贝,使用数组时会将其转换成指针
返回类型和return语句
返回数组指针
type (*func(par))[dim];//形参列表先于数组维度
从内到外>>从右到左
int odd[]={1,3,5,7,9};
decltype(odd) *arrptr(int i)//decltype并不负责把数组转换成相应的指针,想要返回指针必须加*
{
.....
}
特殊用途语言特性
默认实参
默认实参只能填补函数调用缺少的尾部实参
window=screen(,,'?');//错误,只能省略尾部实参
constexpr函数
constexpr函数不一定返回常量表达式
调试帮助
assert预处理宏
assert(expr);//表达式为假,assert输出信息,终止程序;为真,什么也不做
NDEBUG预处理变量
定义了NDEBUG,则assert什么也不做
函数指针
bool lengthCompare(const string &,const string &);
bool (*pf)(const string &,const string &);//pf指向函数lengthCompare
函数指针形参
和数组一样,函数作为形参时,自动转化成指向函数的指针
返回指向函数的指针
必须把返回类型写成指针形式