1.
class Test
{public:
explicit Test(int a)
:ma(a)
{}
private:
int ma;
};
int main()
{
Test tetst(20);
test = 30;//Test = (int ==> Test) 隐式生成临时对象
return 0;
}
像上面会有隐式生成临时对象,这样的话会有安全隐患存在.而这是系统编译安装推演来处理,是不可控的因素,为了防止这个现象,用explicit函数
explicit作用:
禁止隐式生成临时对象
2.int main()
{
const Test test(10, 20);
/*
不得不修改常量
*/
test.ma = 100;
test.mb = 200;
return 0;
}
volatile 作用:
静止编译器优化
不可控的因素
多线程
3.
class Test
{
public:
Test(int a, int b)
{
ma = a;
mb = b;
}
public:
mutable int ma;//去除常性
int mb;
};
mutable作用
去除常性
智能指针
4.strncmp 比较字符串前n个字符是否相等 相等返回0
5.strcmp比较字符串是否相等 相等返回0
6.strcat()字符串拼接
7.strcpy字符串拷贝