<span style="font-size:18px;">//成员函数指针
#include <iostream>
using namespace std;
//全局函数
void test (){
cout << "this is test" << endl;
}
void test2 (int a){
cout << "this is test22222" << endl;
}
//结构体
struct Date{
int year;
int month;
int day;
//成员函数
void show(){
cout << year << ' ' << month << ' ' << day << endl;
}
//有参
void show2(int a,int b){
cout << "这是有参的成员函数" << endl;
cout << year << '-' << month << '-' << day << ' ' << a+b << endl;
}
//无参
void showYear(){
cout << "今年是 " << year << " 年!" << endl;
}
int add(){
return year + month + day;
}
int sub(){
retu
C++成员函数指针与其应用场景
最新推荐文章于 2024-07-10 07:08:21 发布
本文深入探讨了C++中的成员函数指针,包括其定义、使用方法和常见应用场景。通过实例解析,阐述了如何将成员函数指针与其他C++特性结合,以实现灵活的代码设计和调用策略。
摘要由CSDN通过智能技术生成