msdn里的C++unary_function的例子
来源:互联网 发布:java开发超市管理系统 编辑:程序博客网 时间:2024/04/30 11:27
// unary_function.cpp
// compile with: /EHsc
//
// Structure used:
// unary_function<int, float> - allows us
// to write operator functions accepting an
// integer and returning floats.
////////////////////////////////////////////
#include <functional>
#include <iostream>
using namespace std ;
/* derive class from unary_function in order to use it */
class unary_test : public unary_function<int,float>
{
public:
float value;
unary_test(){value=10.0;}
unary_test(float x){value=x;}
result_type operator*(argument_type x);
result_type operator-(argument_type x);
};
/* You can now easily create operators that accept */
/* an int and return a float. */
unary_test::result_type unary_test::operator*(unary_test::argument_type x)
{
float tmp = value * (float)x;
cout << "Value after * is " << tmp << endl ;
return value;
}
unary_test::result_type unary_test::operator-(unary_test::argument_type x)
{
float tmp = value - (float)x;
cout << "Value after minus is " << tmp << endl ;
return tmp;
}
int main(void)
{
unary_test item;
unary_test item2(18.0);
cout << "Begin" << endl ;
cout.setf(ios::fixed) ;
item = item * 2;
item2 = item2 - 5;
return 0;
}
/*
Output
Begin
Value after * is 20.000000
Value after minus is 13.000000
*/
- msdn里的C++unary_function的例子
- MSDN处理异常的例子
- windows中目录字符串处理函数, MSDN里有使用的例子
- fms里c/s的一个例子
- MSDN里关于WinMain的描述
- 转MSDN里的CWnd::OnHScroll
- 微软MSDN中ado的例子
- MSDN 上的Hook例子2
- MSDN中SetWindowsHookEx的例子代码
- C 中枚举(项目里遇到的)例子
- MSDN自带的例子“CTRLTEST”学习CBitmapButton的用法
- 在MSDN里创建胖客户端程序时MSDN的一个错误
- 【存档】msdn里关于字符串转换的一段
- 油猴子脚本【隐藏MSDN里的代码成员】
- Spring里的IOC例子
- cJSON源码里的例子
- MSDN上用DataSet修改数据库的例子
- 写给初学者:一个调试、利用msdn的经典例子
- 在blog中显示天气预报、日历、时钟、MSN、QQ在线状态
- 终于把用cvsnt+TortoiseCVS把cvs搞定了
- 全面认识USB技术的精髓(二)
- NAS存储产品介绍
- Cisco路由入侵艺术
- msdn里的C++unary_function的例子
- 恩,还没什么东西。
- 利用FSO取得图像文件信息
- Java XML API 漫谈
- 请教一下:Windows任务管理器中显示的进程占用的内存是什么内存? 分配的还是使用的? 另外,最小化一个进程的时候为什么其占用的内存会大大降低?谢谢
- VBScript编码规范格式
- 巧用in关键字实现数据的批量删除
- SQL 中自己创建函数,分割字符串
- Linux下的硬件驱动——USB设备(下)(驱动开发部分)