六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 60|回复: 0

原创C++笔试题,查找一个字符串类不正确的地方

[复制链接]

升级  0.67%

11

主题

11

主题

11

主题

秀才

Rank: 2

积分
51
 楼主| 发表于 2013-2-4 22:09:37 | 显示全部楼层 |阅读模式
#include <stdlib.h>#include <string.h>class TSimpleString{public:static const size_t npos;TSimpleString() : m_pStorage(NULL) {}TSimpleString(const TSimpleString& s) { assign(s.m_pStorage); }TSimpleString(const char * s, size_t n = npos) { assign(s, n); }boolempty(void) { return (m_pStorage == NULL); }voidclear(void);voidassign(const char * s, size_t n = npos);const char *c_str(void) { return (m_pStorage == NULL) ? "" : m_pStorage; }private:char *m_pStorage;};void TSimpleString::clear(){if( m_pStorage != NULL )delete m_pStorage;}void TSimpleString::assign(const char * s, size_t n){if( m_pStorage == s )return;clear();if( n == npos )n = ( s == NULL ? 0 : strlen(s) );if( n > 0 ){m_pStorage = new char [n];for( size_t i = 0; i < n; ++i )m_pStorage[i] = s[i];}}

提示:
1,有1处编译错误
2,大概有8处严重错误
3,有2处可改进的地方

注:可能有些错误我自己还没发现
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表