2013年2月26日
摘要: String的赋值函数operator=的实现如下:CMystring& CMystring::operator=( const CMystring& other ) { if( this == &other ) // 检查自身赋值 { return *this; }if( m_data != NULL ) { delete []m_data; // 释放原有的空间 m_data = NULL; }m_data = new char[ strlen(other.m_data)+1 ]; if( m_data == NULL ) { cout << " 阅读全文
posted @ 2013-02-26 17:39 侠骨豪情 阅读(440) 评论(0) 推荐(1) 编辑
摘要: 一直对C++中的delete和delete[]的区别不甚了解,今天遇到了,上网查了一下,得出了结论。做个备份,以免丢失。C++告诉我们在回收用 new 分配的单个对象的内存空间的时候用 delete,回收用 new[] 分配的一组对象的内存空间的时候用 delete[]。 关于 new[] 和 delete[],其中又分为两种情况:(1) 为基本数据类型分配和回收空间;(2) 为自定义类型分配和回收空间。请看下面的程序。?12345678910111213141516171819202122#include ;usingnamespacestd;classT {public:T() { cou 阅读全文
posted @ 2013-02-26 16:28 侠骨豪情 阅读(376) 评论(0) 推荐(1) 编辑