0
点赞
收藏
分享

微信扫一扫

c++,静态成员函数

林肯公园_97cc 2022-04-14 阅读 134
c++

#include <iostream>
#include<stdlib.h>
using namespace std;
//静态成员函数
//所有的对象共享同一个函数
//静态成员函数只能访问静态成员变量
class Person
{
public:
    static void func()
    {
        m_a=100;
        //m_b=200;
        cout<<"static void func调用"<<endl;
    }
    static int m_a;
    int m_b;
private:
    static void func02()
    {
        cout<<"static void func02的调用"<<endl;
    }

};
int Person::m_a=0; //初始化
//
void test()
{
    Person p;
    p.func();
    Person::func();
    //Person::func02();

}
int main()
{
    test();
    system("pause");
    return 0;
}

举报

相关推荐

0 条评论