一个简单一些的,看看行不
#include
using namespace std;
class A
{
public:
A ();//构造函数
~A ();//析构函数
void inti (int);//为对象赋值
void display ();
private:
int * ptr;
};
A::A ()
{
cout<<"执行构造函数!"<
}
A::~A ()
{
cout<<"执行析构函数!"<
}
void A::inti (int value)
{
*ptr = value;
}
void A::display ()
{
cout<<"对象的值为"<<*ptr<
int main ()
{
int n = 5;
A a;
a.inti (n);
a.display ();
return 0;
}