c++ 函数指针作为返回值,链式编程
2016-08-09 15:23
302 查看
作为一名刚转入c++行列的程序员,不知道这样写合理不合理,主要是为了熟练函数指针。
#include <stdio.h> #include <tchar.h> #include <string> #include <iostream> using namespace std; void haveBreakfast(string food)//吃早饭 { cout << "开始吃早饭,吃了" << food << endl; } void (* brush())(string food)//刷牙 { cout << "刷牙" << "\n↓" << endl; return haveBreakfast; } void (* (* getUp())())(string food)//起床 { cout << "起床" << "\n↓" << endl; return brush; } void ( * (* (* openEyes(string person))())())(string food)//睁开眼 { cout << person << "\n↓\n" << "睁开眼" << "\n↓" << endl; return getUp; } int _tmain(int argc, _TCHAR* argv[]) { openEyes("张小明")()()("鸡蛋"); getchar(); return 0; }
相关文章推荐
- 【从C到C++学习笔记】引用/const引用/引用传递/引用作为函数返回值/引用和指针的区别
- C++指针与函数—指针作为参数和返回值
- C++ 引用和指针作为函数参数的例子。请不要拍砖
- C++ 常量指针或者常量引用作为函数参数传递的原因
- C++模板编程->函数指针模板参数
- Python的函数式编程-传入函数、排序算法、函数作为返回值、匿名函数、偏函数、装饰器
- c++将引用或者是指针作为函数参数实现实参的运算
- c++ 指针作为函数参数传递
- C++ 函数指针 函数名作为参数
- C++模板编程->函数指针模板参数
- C++传递对象函数指针作为参数
- 【C++编程技巧】函数多个返回值
- C++函数参数和返回值三种传递方式:值传递、指针传递和引用传递(着重理解)
- C++指针作为函数的参数进行传递时注意的问题
- C++模板编程->成员函数指针模板参数
- C++ 指针作为函数参数介绍
- c++ 成员函数作为函数指针参数传入
- ”引用 & 指针“ -- 作为函数的参数和返回值小结
- 我的c++学习(12)指针作为函数参数
- [C++]关于指针作为函数参数传递