1. public:就是可以被程序中的其它函数调用(如main函数,其他类的成员函数)。
2.private:只能被自己类或友元的成员函数访问
3. Constructors :
(1)cannot return values, so they cannot specify a return type (not even void).
(2)Normally, constructors are declared public.
(3)The member initializer list executes before the body of the constructor executes.
(4)constructor可以overloaded(重载);
(5)调用constructor:
可用list initializer:
4.<string>中的成员函数substr(起始位置,字符数)
e.g. string2=string1.substr(0,25);
5.this指针:
(1)静态成员函数没有this指针
(2)this指针的类型取决于对象的类型和使用this指针的成员函数是否为const。
(3)this指针的作用:
避免名字冲突;实现级联
6.setfill:
7.destructor:
8.构造函数和析构函数调用的顺序:
构造函数的调用就是按照定义顺序来的,而析构函数的顺序(每一部分与构造函数调用顺序相反):非静态局部->main->静态->全局
(1)定义在全局中的对象的构造函数在main之前被调用:
(2)局部对象按顺序(在进入block和离开block时调用构造函数和析构函数)
其中,静态局部对象在到定义处调用构造函数,而在main结束后才会调用析构函数
9.想对const变量动手只能是const成员函数
10. 数据成员按照他们在类中定义的顺序被构造,而不是构造初始化列表。
11. 友元函数可以访问类的公有和私有成员
12.static member function不能声明为const(理解:const是指不能改变对象的成员,但是静态数据成员不属于某一具体的对象;const对有this指针的函数才有意义)
静态成员函数只能对静态数据成员进行操作
整理不易,亲亲点个赞呗~~