关于静态成员函数的一个问题,请大佬帮我看看。
#include<iostream>#include<string.h>
using namespace std;
class student
{
private:
static int total;
int num;
char name[20];
public:
student(){total++;}
~student(){total--;}
student(int n,const char *p="wang");
void getname();
int getnum();
static void Print();
};
int student::total=0;
student::student(int n,const char *p)
{
num=n;
strcpy(name,p);
total++;
}
void student::getname()
{
cout<<name<<endl;
}
int student::getnum()
{
return num;
}
void student::Print()
{
cout<<"The number of all students:"<<total<<endl;
}
int main()
{
student::Print();
student *P=new student(13);
student::Print();
P->Print();
delete P;
P->Print(); //????????
student s[2];
student::Print();
s[1].Print();
return 0;
}
问:为什么对象指针P被释放后,还能正确调用静态成员函数?