dot asterisk operator in c++

后端 未结 2 1040
长发绾君心
长发绾君心 2020-12-25 12:04

is there, and if, what it does?

.*
2条回答
  •  时光说笑
    2020-12-25 12:10

    You may come across that operator when using member pointers:

    struct foo
    {
        void bar(void);
    };
    
    typedef void (foo::*func_ptr)(void);
    
    func_ptr fptr = &foo::bar;
    foo f;
    
    (f.*fptr)(); // call
    

    Also related is the ->* operator:

    func_ptr fptr = &foo::bar;
    foo f;
    foo* fp = &f;
    
    (fp->*fptr)(); // call
    

提交回复
热议问题