很简单的代码。主要体现类的构造函数与系构函数。
代码如下:
#include<iostream>
using namespace std;
class myclass
{
int a,b;
public:
myclass();
~myclass();
void myprintf();
};
myclass::myclass()
{
cout<<"consturctor/n";
a=0;
b=1;
}
myclass::~myclass()
{
cout<<"destructor/n";
}
void myclass::myprintf()
{
cout<<"a is "<<a<<endl;
cout<<"b is "<<b<<endl;
}
int main()
{
myclass first;
first.myprintf();
return EXIT_SUCCESS;
}