语言 的标准库函数, 是 的运算符。它们
都可用于申请动态内存和释放内存。
、对于非内部数据类型的对象而言,光用 无法满足动态对象的要求。对象在
创建的同时要自动执行构造函数,对象在消亡之前要自动执行析构函数。由于
是库函数而不是运算符,不在编译器控制权限之内,不能够把执行构造函数和析构函
数的任务强加于 。
、因此 语言 需要一个能完成动态内存分配和初始化工作的运算符 ,以一个能完
成清理与释放内存工作的运算符 。注意 不是库函数。 、 程序
经常要调用
函数 ,而 程序只能用 管理动态内存。
可以认为是 加构造函数的执行。 出来的指针是直接带类型信息的。而
返回的都是 指针。
是运算符, 是函数 与 是 语言的标准库函
数, 是 的运算符。它们都可用于申请动态内存和释放内存。 对于非内
部数据类型的对象而言,光用 无法满足动态对象的要求。对象在创建的同时
要自动执行构造函数,对象在消亡之前要自动执行析构函数。由于 是库函数
而不是运算符,不在编译器控制权限之内,不能够把执行构造函数和析构函数的任务强加
于 。 因此 语言需要一个能完成动态内存分配和初始化工作的运算符
,以及一个能完成清理与释放内存工作的运算符 。注意 不是库函
数
与 区别
中的两个功能:
这两个关键字可以一起使用当一起使用时它们的先后顺序是没有限制的谁在前面都一
样 是指常量 则表示静态变量它们一起使用时则表示一个静态常量
当你声明一个变量并初始化后你不想在后面的程序中对该变量进行修改的话 你就可以用
修饰符来修饰它它告诉编译器这是一个常量如果你对常量作了修改编译的时候就
会通不过而静态变量则是在你声明之后这个变量就一直常驻内存直到程序结束它才会被
销毁例如你在一个自定义函数中定义了一个静态变量当这个函数被调用结束它里的静态
变量依然存在当第二次调用该函数时这个变量并不会重新被分配内存它的值则是上一次
调用后它的值
对 关键字的重用:
主要指静态数据成员/成员函数。
表示属于一个类而不是属于此类的任何特定对象的变量和函数 这是与普通成员函数的最
大区别也是其应用所在比如在对某一个类的对象进行计数时计数生成多少个类的实例
就可以用到静态数据成员在这里面 既不是限定作用域的也不是扩展生存期的作
用而是指示变量函数在此类中的唯一性这也是”属于一个类而不是属于此类的任何特定
对象的变量和函数”的含义因为它是对整个类来说是唯一的因此不可能属于某一个实例
对象的针对静态数据成员而言成员函数不管是否是 在内存中只有一个副本普
通成员函数调用时需要传入 指针 成员函数调用时没有 指针
数据成员的初始化:
初始化在类体外进行,而前面不加 ,以免与一般静态变量或对象相混淆。
初始化时不加该成员的访问权限控制符 , 等。
初始化时使用作用域运算符来标明它所属类,因此,静态数据成员是类的成员,而不
是对象的成员。