主题:[原创]谢谢了,有个问题想不明白
我想问一下。这个程序的#include<iostream.h>
class Exercise {
public:
Exercise(int n=0);
Exercise(const Exercise &);
void display();
void m(int);
private:
int *num;
};
Exercise::Exercise(const Exercise &t)
{
num=mew int;
*num=*t.num;
}
Exercised::Exercise(int n);
{
num=new int;
*num=n;
}
void Exercise::display()
{
cout<<"num="<<num<<endl;
}
void Exercise::m(int t)
{
*num=t;
}
int main()
{
Exercise a(1),c=a;
c.display();
a.m(3);
c.display();
c=a;
a.m(10);
c.display();
return 0;
}
运行结果
class Exercise {
public:
Exercise(int n=0);
Exercise(const Exercise &);
void display();
void m(int);
private:
int *num;
};
Exercise::Exercise(const Exercise &t)
{
num=mew int;
*num=*t.num;
}
Exercised::Exercise(int n);
{
num=new int;
*num=n;
}
void Exercise::display()
{
cout<<"num="<<num<<endl;
}
void Exercise::m(int t)
{
*num=t;
}
int main()
{
Exercise a(1),c=a;
c.display();
a.m(3);
c.display();
c=a;
a.m(10);
c.display();
return 0;
}
运行结果