指向成员函数的指针
//
// main.cpp
// testvoidmain
//
// Created by mac on 2019/4/11.
// Copyright © 2019年 mac. All rights reserved.
// 1.只有成员函数才能有const限定符
// 2.脑袋怎么总是混乱
// 3.在类内部定义指向函数的指针有点蠢?
#include <iostream>
using namespace std;
template <class genType>
class classf{
public:
classf(){
}
~classf(){}
genType fun1(genType &);
genType (classf:: *p)(genType &)=&classf::fun1;
};
template<class genType>
genType classf<genType>::fun1(genType &a){
return a;
}
int main(int argc, const char * argv[]) {
classf<int> cf,*q=&cf;
int a=3;
cout<<cf.fun1(a)<<endl;
cout<<(cf.*(cf.p))(a)<<endl;
cout << "Hello, World!\n";
return 0;
}
运行结果
3
3
Hello, World!
Program ended with exit code: 0
未经本人准许,禁止转载.