构造函数 析构函数类的初始化、析构、赋值.ppt

构造函数 析构函数类的初始化、析构、赋值.ppt

str str s1 s2 t h i s \0 t h a t \0 String S1, S2; S1= “this”; S2 = “that”; str str s1 s2 t h i s \0 t h a t \0 S1 = S2; 深复制/深拷贝 ?将一个对象中指针变量指向的内容, ?复制到另一个对象中指针成员对象指向的地方 重载赋值运算符的意义 –浅复制和深复制 StringS1, S2; S1= “this”; S2= “that”; S1= S2; str str s1 s2 t h i s \0 t h a t \0 String S1, S2; S1= “this”; S2 = “that”; str str s1 s2 t h a t \0 t h a t \0 S1 = S2; StringS1, S2; S1= “this”; S2= “that”; S1= S2; 在class String里添加成员函数: String operator = ( const String s ) { if ( str ) delete [] str; str = new char[strlen(s.s

文档评论(0)

1亿VIP精品文档

相关文档