各位大哥帮帮我,这道题是讲的什么,看了很长时间还是没看懂

piao_yi 2009-03-20 06:07:24
过几天就要交了,小弟刚学C++,英文的题实在理解不好,各位大哥一定帮忙分析下啊,

The following class is the my_string class that has reference semantics for copying. This class has shallow copy semantics because pointer assignment replaces copying. The techniques illustrated are common for this type of aggregate. We use the class str_obj to create object values. The type str_obj is a required implmentation detail for my_string. It could not be directly placed in my_string without destroying the potential many_to_one relationship between objects of type my_string and referenced values of type str_obj. The values of my_string are in the class str_obj, which is an auxiliary class for my_string's use only. The publicly used class my_string handles the str_obj instances and is called a handler class.

class str_obj
{
public:
int ref_cnt;
char* s;
str_obj() : ref_cnt(1), len(0)
{
s = new char[1];
assert(s != 0);
s[0] = 0;
}
str_obj(const char* p) : ref_cnt(1)
{
len = strlen(p);
s=new char[len+1];
assert(s != 0);
strcpy(s, p);
}
~str_obj() { delete [] s; }
private:
int len;
};

class my_string
{
public:
my_string()
{
st = new str_obj;
assert(st != 0);
}
my_string(const char* p)
{
st = new str_obj(p);
assert(st != 0);
}
~my_string()
{
if (--st -> ref_cnt ==0)
delete st;
}
void print() const { cout << st->s; }
};

Implement:

overloaded assignment operator = for my_string;
overloaded subscript operator [] to return the ith character in the my_string. If there is no such character, the value -1 is to be returned.
overloaded the function call operator () to operate substring. The notation is my_string(from, to), where from is the beginning of the substring and to is the end. Use this to search a string for a character sequence and return true if the subsequence is found.
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
MagicCaptain 2009-03-22
  • 打赏
  • 举报
回复
BIT,否?
yzxtxwd 2009-03-21
  • 打赏
  • 举报
回复
搭车同求。。。
piao_yi 2009-03-20
  • 打赏
  • 举报
回复
在线等待帮助

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧