亚信联创20110917笔试题
亚信联创2011.9.17招聘会笔试题
1、对于如下程序:
view plain
, #include
, using namespace std;
, class A
, {
, public:
, A()
, {
, cout<<"A"<内容 ,, assert(m_data != NULL);
,, strcpy(m_data,str);
,, }
,, }
,,
,, String::String(const String &other) //拷贝构造函数 ,? {
,, m_data = new char[strlen(other.m_data)+1]; ,, assert(m_data != NULL);
,, strcpy(m_data,other.m_data);
,, }
,,
,, String::~String(void) //析构函数 ,, {
,, if(m_data != NULL)
,, {
,? delete []m_data;
,, m_data = NULL;
,, }
,, }
,,
,, String & String::operator=(const String &other) //赋值函数
,, {
,, if(&other == this) //如果对象与other是同一个对象
,, return *this;
,, delete []m_data; //释放堆内存 ,? m_data = new char[strlen(other.m_data)+1]; ,, assert(m_data != NULL);
,, strcpy(m_data,other.m_data); ,, return *this;
,, }