C++对象参数与返回
来源:互联网 发布:bpm测试软件ios 编辑:程序博客网 时间:2024/05/17 01:25
class String
{
public:
String(const char *str=NULL);
String(const char &other);
~String(void);
String & operate=(const String &other);
private:
char *m_data;
};
String::~String(void)
{
delete []m_data;
}
//构造
String::String(const char *str)
{
if (str==NULL)
{
m_data=new char[1];
*m_data='/0';
}
else
{
int length=strlen(str);
m_data=new char[length+1];
strcpy(m_data,str);
}
}
//拷贝
String::String(const String &other)
{
int length=strlen(other.m_data);
m_data=new char[length+1];
strcpy(m_data,other.m_data);
}
//赋值函数
String & String::operate=(const String &other)
{
if(this==&other)
return *this;
delete [] m_data;
int length=strlen(other.m_data);
m_data=new char[length+1];
strcpy(m_data,other.m_data);
return *this;
}
void main()
{
String s1("hello");
String s2=s1;
String s3("hello");
String s4=("like");
s3=s4;
cout<<*(s1.m_mata)
- C++对象参数与返回
- 引用参数与引用返回值,临时对象
- 引用参数与引用返回值,临时对象
- 面向对象之形式参数与返回值问题
- C函数参数传递与返回值传递
- C语言(23)------函数返回值与参数列表
- 返回值与参数
- C++:返回对象
- C返回多个参数
- C++,当函数参数或者返回值是对象......(★firecat推荐★)
- 函数参数与返回值
- SpringMVC 接收与返回参数
- hjr教程-C(一):函数调用与参数传递与返回值
- 8.1面向对象(形式参数与返回值,修饰符,内部类)
- SqlCommand对象的返回参数使用
- 对象与函数参数
- 方法与对象参数
- tc2.0环境下的C语言研究-变量与参数返回值
- ASP.NET Master Page中的title
- P1201高低位交换解题报告
- 万能makefile
- 微软技术通 - MSDN他最熟
- Subversion和TortoiseSVN安装与配置
- C++对象参数与返回
- lib和dll文件的区别和联系
- SOA学习笔记三:SCA分析
- 微软SQLServer密码管理的危险判断
- Linux对Linux传文件
- Eclipse中编 C++程序报出 usr include/c++/4.2/backward...错误
- Flex中利用ByteArray与BitmapData互相转换实现图片的二进制保存与复原
- 规划职业生涯经验谈
- 面向对象的设计原则