面试C++试题[7]

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

本文简介:选择自 x1001 的 blog

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

    strcpy(m_data, other.m_data);        

}

// 赋值函数

    string & string::operate =(const string &other)    // 13分

    {  

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

        if(this == &other)

           return *this;

   

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

        delete [] m_data;

      

       // (3)分配新的内存资源,并复制内容 // 3分

    int length = strlen(other.m_data); 

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

        strcpy(m_data, other.m_data);

      

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

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

go top