数据结构6 C++类串.pptVIP

  • 9
  • 0
  • 约6.61千字
  • 约 27页
  • 2018-07-18 发布于湖北
  • 举报
19. C++类串 类串与类串连接 * String String::operator+(const String cs)const { String w; delete[]w.str; w.size=size+cs.size; w.str=new char[w.size+1]; if(w.str==NULL) Error(operator+:overflow!); strcpy(w.str,str); strcat(w.str,cs.str); return(w); } 为什么不用引用? 因为W是String类型,在函数执行后会调用“析构函数”进行撤销,就造成引用NULL的情况,而NULL是不能被引用的 String String::operator+(const *this, const String cs) 19. C++类串 类串与C串连接 * String String::operator+(const char *c)const { String w; delete[]w.str; w.size=size+strlen(c); w.str=new char[w.size+1]; if(w.str==NULL) Error(operator+:overflow!); strcpy(w.str,str); strcat(w.str,c)

文档评论(0)

1亿VIP精品文档

相关文档