惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
U
Unit 42
aimingoo的专栏
aimingoo的专栏
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
M
MIT News - Artificial intelligence
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
IT之家
IT之家
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News

博客园 - pipicfan

unity性能优化之Drawcall优化 谈谈我是如何面试技术人员的 Shader中颜色的加法和乘法的区别 unity性能优化-实际开发中需要注意的点 向字符数组中插入一个字符 cocos2dx 新手引导 c++面试题 c++实现委托 屁屁桌面管理 War3Tool dota改键v3.3版 魔兽全屏改键工具 很犀利的错误 关于vs2003环境支持win7 的 IP设置 自己的毕业设计windows管理软件 很容易犯的错误 敏感词过滤和谐社会1.0版 宿舍计费系统105加强版 用C++ 设计一个不能被继承的类 (转)字符编码笔记:ASCII,Unicode和UTF-8
自己实现string类
pipicfan · 2012-12-06 · via 博客园 - pipicfan

mystring.h

 1 #pragma once
 2 
 3 class mystring
 4 {
 5 public:
 6     mystring( const char *str=NULL);
 7     mystring(const mystring  &others);
 8     
 9     mystring  &operator = (const mystring & others);
10     virtual ~mystring(void);
11 
12     void disply();
13    
14 private:
15     char *m_data;
16 
17 
18 };

mystring.cpp

 1 mystring::mystring( const char *str/*=NULL*/ )
 2 {
 3     
 4     m_data = new char [strlen(str)+1];
 5 
 6 
 7     if(!m_data)
 8     {
 9         
10         return ;
11     }
12 
13     strcpy(m_data,str);
14 
15 }
16 
17 mystring::mystring( const mystring &others )
18 {
19 
20     m_data = new char [strlen(others.m_data)+1];
21 
22 
23     if(!m_data)
24     {
25 
26         return ;
27     }
28 
29     strcpy(m_data,others.m_data);
30 }
31 
32 mystring::~mystring(void)
33 {
34 
35     if(m_data)
36     {
37         delete [] m_data;
38         m_data = NULL;
39     }
40 }
41 
42 void mystring::disply()
43 {
44 
45     cout<<m_data<<endl;
46 }
47 
48 mystring  & mystring::operator=( const mystring & others )
49 {
50 
51    if(this== &others)
52    {
53      return *this;
54    }
55    
56 
57    if(m_data!=NULL)
58    {
59        delete  []m_data;
60    }
61 
62    m_data = new char [strlen(others.m_data)+1];
63    strcpy(m_data,others.m_data);
64    return *this;
65 
66 }
67 
68 
69 int _tmain()
70 
71 {
72 
73 
74     mystring s("sdaadssa");
75 
76     mystring p("dasda");
77 
78 s = p;
79 
80     s.disply();
81     return 0;
82 
83 }

我自豪 我是一名软件工程师。

posted @ 2012-12-06 10:23  pipicfan  阅读(483)  评论()    收藏  举报