我正在审查一个测试,我正在处理我的个人项目,但我正在进行增量开发。我想在大学学习中取得好成绩。
它在我的 ostream 运算符上出现了故障,并且我的虚拟功能不起作用,除非它没有 virtual 。
#include"MyString.h"
MyString::MyString( ) //constructor
{
size=0;
capacity=1;
data=new char[capacity];
}
MyString::MyString(char * n) //copy constructor
{
size=strlen(n);
capacity=strlen(n)+1;
data=new char[capacity];
strcpy(data,n);
}
MyString::MyString(const MyString &right) //
{
size=strlen(right.data);
capacity=strlen(right.data)+1;
data=new char [capacity];
strcpy(data,right.data);
}
MyString::~MyString( )
{
delete [] data;
}
MyString MyString::operator = (const MyString& s)
{
if(this!=&s)
{
MyString temp=data;
delete [] data;
size=strlen(s.data);
capacity=size+1;
data= new char [capacity];
strcpy(data,s.data);
}
}
MyString& MyString::append(const MyString& s)
{
if(this!=&s)
{
strcat(data,s.data);
}
}
MyString& MyString::erase()
{
}
MyString MyString::operator + (const MyString&)const
{
}
bool MyString::operator == (const MyString&)
{
}
bool MyString::operator < (const MyString&)
{
}
bool MyString::operator > (const MyString&)
{
}
bool MyString::operator <= (const MyString&)
{
}
bool MyString::operator >= (const MyString&)
{
}
bool MyString::operator != (const MyString&)
{
}
void MyString::operator += (const MyString&)
{
}
char& MyString::operator [ ] (int)
{
}
void MyString::getline(istream&)
{
}
int MyString::length( ) const
{
return strlen(data);
}
ostream& operator<<(ostream& out, MyString& s){
out<<s;
return out;
}
// int MyString::getCapacity(){return capacity;}