函数:
如果函数已经被声明为inline 内联 则函数体可能已经在编译期间它的调用点上就被展开如果没有被声明为inline 则函数在运行时才被调用。
内联函数:
inline 内联函数给出了一种解决方案若一个函数被指定为inline 函数则它将在程序中每个调用点上被内联地展开。inline int min( int v1, int v2 ) { /* ... */ }
链接指示符:
程序员用链接指示符(linkage directive) 告诉编译器该函数是用其他的程序设计语言编写的,链接指示符有两种形式既可以是单一语句(single statement )形式,也可以是复
合语句(compound statement) 形式 ,链接指示符不能出现在函数体中。
// 单一语句形式的链接指示符
extern "C" void exit(int);
// 复合语句形式的链接指示符
extern "C" {
int printf( const char* ... );
int scanf( const char* ... );
}
// 复合语句形式的链接指示符
extern "C" {
#include <cmath>
}
如果一个函数在同一文件中不只被声明一次,则链接指示符可以出现在每个声明中,它也可以只出现在函数的第一次声明中,在这种情况下第二个及以后的声明都接受第一个声明中链接指示符指定的链接规则。
main()命令处理行选项
int main( int argc, char *argv[] ) { ... }
program_name [-d] [-h] [-v]
[-o output_file] [-l limit_value]
file_name
[ file_name [file_name [ ... ]
域
C++ 支持三种形式的域局部域、名字空间域、以及类域。
auto_ptr:#include <memory>
auto_ptr 是C++ 标准库提供的类模板,它可以帮助程序员自动管理用new 表达式动态分配的单个对象 。auto_ptr 对象被初始化为指向由new 表达式创建的动态分配对象,当auto_ptr 对象的生命期结束时动态分配的对象被自动释放。
auto_ptr 对象的定义有下列三种形式 , type_pointed_to 代表由new 表达式创建的对象的类型:
auto_ptr< type_pointed_to > identifier( ptr_allocated_by_new );
auto_ptr< type_pointed_to > identifier( auto_ptr_of_same_type );
auto_ptr< type_pointed_to > identifier;
pi 被初始化为由new 表达式创建的对象的地址,且该对象的初始化值为1024。
auto_ptr< int > pi( new int( 1024 ) );
定位new表达式
new 表达式的第三种形式可以允许程序员要求将对象创建在已经被分配好的内存中。new (place_address地址) type -specifier 对象