#include <iostream>
using namespace std;
#include <cstdio>

class Student{
public:
    Student(const string& name):m_name(name){}
    string m_name;
    static int m_age;

};
int Student::m_age=20;
int main(void) {
    #成员指针
    string Student::*pname = &Student::m_name;
    #指向静态成员的指针
    int *p_sage = &Student::m_age;
    Student s1("zhangfei");
    cout << s1.*pname << endl;
    cout << *p_sage << endl;
    
    Student* p = &s1;
    cout << p->*pname << endl;
    
}

静态成员变量 m_age:它的生命周期:整个源程序,作用域:Student类

所以调用m_age有两种方法,s1.m_age或者Student.m_age都可以


指向静态成员变量的指针p_sage:它指向的是一个静态成员变量,

它的生命周期:整个源程序,作用域:整个作用域,

所以 int Student::*psage = &Student::m_age;是错误的

正确写法:int *p_sage = &Student::m_age;

调用的时候只能*p_sage 不能 s1.*p_sage