member function pointers and pointers to static member functions

Source: Internet
Author: User

#include  <iostream>using namespace std;class Student{public:     Student (const string& name): M_name (name) {}    void who (void) {         cout << m_name << endl;     }    string m_name;    static int s_add (int &NBSP;A,INT&NBSP;B) {        return a+b;    }} ; Int main (void) {    //member function pointer     void  (Student::* pwho) (void) &NBSP;=&NBSP;&AMP;STUDENT::WHO;&NBSP;&NBSP;&NBSP;&NBSP;STUDENT&NBSP;S1 ("Zhnangfei");     STUDENT&NBSP;S2 ("Zhaoyun");     (s1.*pwho) ();    student* ps  = &s2;     (ps->*pwho) ();     //pointer to static member function      int  (*Padd) (Int,int)  = Student::s_add;    //int  (Student::* padd1) (int,int)  =  Student::s_add; error     cout << padd (100,200)  <<  endl;    return 0;} Pointer to member function (that is, function pointer): Type   () (parameter type)  = & class Name:: member function name (note that the address character must be added before the class name & or an error) pointer to a static member function (or function pointer): type   () (parameter type)  = student::s_add (note type can be added without &)


This article is from the "12208412" blog, please be sure to keep this source http://12218412.blog.51cto.com/12208412/1866470

member function pointers and pointers to static member functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.