面试C++试题[13]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 x1001 的 blog

       int length = strlen(other.m_data);    

       m_data = new char[length+1];      // 若能加 null 判断则更好   

       strcpy(m_data, other.m_data);        

}

// 赋值函数

       string & string::operator =(const string &other)    // 13

       {    

              // (1) 检查自赋值                     // 4

              if(this == &other)

                     return *this;

      

// (2) 释放原有的内存资源            // 3

              delete [] m_data;

本文关键:C++,林锐,面试试题
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top