问题描述
这是fn ptrs的好用吗?
#include< iostream>
#include< cstdlib>
using namespace std;
typedef void(* v_v_fptr)();
void Error(){cout<< "错误" << endl;}
void Success(){cout<< "成功" << endl;}
v_v_fptr select(bool arg){if(arg == true)return success;否则返回
错误;}
int main()
{
bool val;
cout<< 1 | 0?: << endl;
cin>> val;
v_v_fptr ptr = select(val);
ptr();
system(" PAUSE");
返回0;
}
或者我应该使用fn objs代替吗?谢谢!!!
Is this a good use of fn ptrs?
#include <iostream>
#include <cstdlib>
using namespace std;
typedef void (*v_v_fptr)();
void Error(){cout << "Error" << endl;}
void Success(){cout << "Success" << endl;}
v_v_fptr select(bool arg){if(arg==true)return Success; else return
Error;}
int main()
{
bool val;
cout << "1|0?: " << endl;
cin >> val;
v_v_fptr ptr=select(val);
ptr();
system("PAUSE");
return 0;
}
Or should I use fn objs instead? Thanks!!!
推荐答案
fn objs更具扩展性,你什么都没有。
fn objs are more extensible and you loose nothing.
这篇关于好好利用fn ptrs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!