基础错误总结

来源:互联网 发布:cnc编程软件powermill 编辑:程序博客网 时间:2024/06/04 01:21

1.

sh: pause: command not found

system(“pause”); 这里使用了windows系统指令,而linux下没有。

  1. string&&c_style_str.
    string是c++中的东西,是一个std中的一个类。打印可以使用cout(从在<<运算符的类,都可以使用)。
    c_style_str是C语言中的东西,打印使用printf(“%s”,c_style_str)。

printf(“%s”) 这里使用的是c风格字符串,不是string,如果这里写入string,会造成显示莫名其妙的东西,很像中文乱码。当然,可以通过string.c_str() 转一下。c风格字符串转string很简单string(c_style_str);

3.运算符重载 A a(1) pk A a=A(1);有区别?
调用方法(A(int))一样,唯一的区别是A a=A(1),时,要求copy constructor(CA& CA::operator=(const CA & ra)) 不能为private。
在网上查了一下资料:为了在class中使用指针是,为了防止浅copy的发生,粗暴一些的方式,将copy constructor 设置为private。也就是说:

CA ca1(1);CA ca2=ca1;/////////////////no equal followCA ca2=CA(1);

隐约记得,这是对匿名对象的优化,不知道如何查,暂时记录一下吧。
下面扩充一下:

    CA  c;//CA()    CA ca(1); //CA(int)    CA xx = ca; //CA(const CA&)    CA yy = CA(2);//CA(int)    CA zz(ca);//CA(const CA&)     xx = yy;  // operator=
原创粉丝点击