主函数输出之后就应该是3,析构函数调用n变成0,但是没有输出了啊,求解答,还有static有什么作用,为什么去掉之后程序出现错误
#include"iostream.h"
class test
{
public:
test()
{
n+=2;
}
~test()
{
n-=3;
}
static int num()
{
return n;
}
private :
static int n;
};
int test::n=1;
int main()
{
test *p=new test;
delete p;
cout<<"n="<<test::num()<<endl;
return 0;
}