const放在只读不写权限的静态成员函数前,VS2019语法不报错。可以正常运行。
class Airplane { public: static int ApNum; public: Airplane() { ApNum++; } const static int GetApNum(){ return ApNum; } }; int Airplane::ApNum = 0; int main(void) { Airplane *Apoint = new Airplane[2]{Airplane(),Airplane()}; cout<<Apoint->GetApNum()<<endl; }