String类成员方法实现
来源:互联网 发布:淘宝怎么推广 编辑:程序博客网 时间:2024/04/30 05:22
//实现String类的成员方法
class String
{
public:
String( const char* str =NULL ) // 普通构造
~String(); //析构
String( const String& other); //拷贝构造函数
String& operater=(const String& other ) //赋值运算重载
private:
char* m_data;
}
String::String(const char* str )
{
if ( str == NULL )
{
m_data = new char[1];
m_data = '\0';
}
else
{
m_data = new char[ strlen(str) + 1 ];
strcpy( m_data,str );
}
}
String::String(const String &other)
{
m_data = new char[ strlen(other.m_data) +1 ];
strcpy( m_data,other.m_data);
}
String&String::operater=(constString&other )
{
if ( this == &other )
{
return *this;//自赋值
}
delete []m_data;
m_data = new char[ strlen(other.m_data )+ 1 ];
strcpy( m_data,other.m_data);
return *this;
}
String::~String()
{
delete []m_data;
}
- String类成员方法实现
- String 类成员函数 实现
- string类的两种实现方法及string的一些成员函数的实现
- String类的常用成员方法.txt
- String类常用的成员方法compareTo()
- String类的成员函数实现
- String类的成员函数实现
- String类成员函数的实现
- String类成员函数的实现
- C++ 字符串 string 类成员函数与方法 小结
- String类常用的成员方法length()和charAt()
- String类 写出类的成员函数实现
- String的类定义如下,实现它的成员函数
- 【笔试】:编程实现C++string 类成员函数
- 【笔试】:编程实现C++string 类成员函数
- 手动实现string类的方法实现
- C++string类型成员函数实现
- String类常用成员函数
- Socket 阻塞模式和非阻塞模式
- 如何通过C的方式在android NDK下面查找本机的mac地址
- 常用的webservice接口 .
- Ubuntu Apache 各项默认目录
- Eclipse设置背景颜色主题插件:Eclipse Color Themes
- String类成员方法实现
- cubieboard + busybox 打造mini系统
- tftp utunut 10.04配置,nfs配置
- android 线程优先级
- 苹果Xcode 证书生成、设置、应用完整图文教程
- OpenGL ES系列之0 – 建立Xcode项目
- 求两个链表的第一个节点
- Matlab常用命令(二)
- Java 文件合并