C ++ Study Notes (5)-member pointer

Source: Internet
Author: User

C ++ not only supports pointers but also adds new pointers
Int A: * P = & A: m; // member pointer

Usage

A A; A. * P;

A * pA = new A; pa-> * P;

Void (A: * f) () = & A: func; // member function pointer
Usage
A A; (A. * p )();

A * pA; (a-> * p )();

#include "stdafx.h"#include <iostream>using namespace std;class A{public:A():m(0){}int m;void print(){cout << "A print()" << endl;}};int _tmain(int argc, _TCHAR* argv[]){A a;int A::*p = &A::m;void (A::*pf)() = &A::print;cout << a.m << endl;cout << a.*p << endl;a.print();(a.*pf)();system("pause");return 0;}

In addition, I have attached a small knowledge about the number of parameters:

# Include <iostream> using namespace STD; // No parameter in C ++ is the same as void F1 () {cout <"hello" <Endl ;} void F2 (void) {return F1 ();} int main () {// F2 (123); // error: Too returns arguments to function 'void F2 () // In this case, the C parameter does not work, but no error is reported. An error is reported in C ++. In vs, when receiving F1 F2 parameters, F1 (); F2 ();} is reported ();}

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.