You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a.f()是属于class A的f函数,不是对象a的.
this: the hidden parameter(pointer to the caller).
C++分配空间但不会把空间里的东西清0.
constructor: 构造对象时初始化。1.名字和类的名字是相同的 2.没有任何返回类型
{Tree t(12)}:打括号表示范围,在这个范围内构造t(把12传进构造函数)。
eg.
Tree(int i){...}
Tree t(12)
destructor: 对象被消灭的时候调用。没有返回类型和参数。{}是析构的范围。
eg.
class Y{
public:
~Y();
};
define进入函数的时候就定义了,构造是运行到那一行在构造。
-sizeof c/ sizeof *c求数组长度
struct Y {float f; int i;Y(int a);};
eg. Y y1[]={Y(1),Y(2),Y(3)};
Default constructor 只要是无参数的都叫这个
new:相当于malloc(先调用)+构造,结果是个地址。
delete:相当于析构(先被调用)+free
new [] 对应delete
(eg. 创建时:int*psome = new int [10]; 释放: delete []psome;)
new 是在操作系统给C++默认分配的空间里再分配(entry table会记录),不是再向操作系统要内存。