class TEST{
public:
    TEST(int v,int v2):a(v),b(v2){

    }
    int a;
    int b;
    void showa()
    {
        std::cout<<"a="<<a<<endl;
    }
    void showb()
    {
        std::cout<<"b="<<b<<endl;
    }
};

void (TEST::*pshow)();
int main()
{
    TEST t(100,200);
     TEST t2(1000,2000);
    int TEST::*pa = &TEST::a;
    std::cout<<"ap="<<t.*pa<<endl;

    pshow = &TEST::showa;
    (t.*pshow)();
    (t2.*pshow)();
    pshow = &TEST::showb;
    (t.*pshow)();
    (t2.*pshow)();
    return 0;
}

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐