#include<iostream>
#include<stdio.h>
using namespace std;
class Class_my
{
public :
Class_my (int ch):i(ch)
{
}
public :
int foo(int ch)
{
return (i + ch);
}
void show(void)
{
cout << i<< endl;
}
private:
int i;
};
int main ()
{
/*
*第一操作数必须指向类类型对象的指针
*第二操作数必须是指向成员的指针类型
*
**/
int temp ;
int (Class_my :: *pmf1)(int ) = &Class_my:: foo; //指向成员的指针pmf用于调用
//成员函数foo()
Class_my c(2);
Class_my *pc = &c;
temp = (pc ->* pmf1)(6); //实际上是函数指针的调用
cout << temp <<endl;
int (Class_my :: *pmf)(int ) = &Class_my:: foo; //指向成员的指针pmf用于调用
int temp1;
Class_my c1(1);
temp1 = (c1 .* pmf)(6);
cout << temp1 <<endl;
return 0;
}
8
7
Press any key to continue
-> * 与 .* 的简单剖析
最新推荐文章于 2024-05-02 20:07:46 发布