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

#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); }

	bool			empty(void) { return (m_pStorage == NULL); }
	void			clear(void);
	void			assign(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处可改进的地方

注:可能有些错误我自己还没发现

你可能感兴趣的:(C++,c,C#)