一道C++题目

2024-12-03 07:33:46
推荐回答(1个)
回答(1):

#include
using namespace std;
class Ex
{
public:
Ex(char *s)
{
len=strlen(s);
p=new char[len+1];
strcpy(p,s);
}
Ex()
{
p=new char[8];
cout<<"****"< }
Ex(const Ex& st)
{
len=sizeof(st);
p=new char[len+1];
strcpy(p,st.p);
}
~Ex()
{
delete []p;

}
void outdata(void)
{
cout<<&len<<","< }
private:
int len;
char *p;
};

int main()
{
Ex x("first");
Ex y=x,z;
x.outdata();
y.outdata();
return 0;

}