strcat函数 在c++类的对象中使用

[复制链接]
查看11 | 回复1 | 2008-11-21 20:23:22 | 显示全部楼层 |阅读模式
有一个类的成员函数是“+”号的重载,若该函数传递的参数是类对象的一个引用,那么怎样使用strcat函数以实现两个字符串的相加(该类有一个char * 的私有成员)请求指点...谢谢 (足下亦可自己定义相关类以说明该函数的具体使用)
最后 str1 = str2 + str3 ; 输出str1
(若参数只有一个类对象的引用...)

回复

使用道具 举报

千问 | 2008-11-21 20:23:22 | 显示全部楼层
class String{char* m_Data;public:friend String& operator+(const String& left, const String& right){
delete []m_Data;
m_Data = new char[left.length() + right.length() + 1];
strcat(m_Data, left.m_Data);
strcat(m_Data, right.m_Data);
return *this;}inline size_t length() const { return strlen(m...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行