总是到strlen这个关键字这里断点
#include<iostream>using namespace std;
class Mystring
{
private:
char *pt;
public:
Mystring(){}
Mystring(char *p )
{
pt = new char[strlen(p)+1]; //就在这里断点 纳闷/..
int i;
for (i = 0; i < strlen(p)+1; i++)
{
*(pt + i) = *(p + i);
}
*(pt + i) = *(p + i);
}
Mystring(Mystring &Object)
{
(*this) = Object;
}
Mystring& operator=(Mystring &Object)
{
pt = new char[strlen(Object.pt) + 1];
int i;
for (i = 0; i <= strlen(Object.pt); i++)
{
*(pt + i) = *(Object.pt + i);
}
*(pt + i) = *(Object.pt + i);
return *this;
}
void Display()
{
cout << "pt = " << pt << endl;
}
};
int main()
{
Mystring Obj1, Obj2("I Love You");
Obj1.Display();
Obj2.Display();
Mystring Obj3;
Obj3 = Obj2;
Obj3.Display();
system("pause");
return 0;