重载函数调用运算符

时间:2014-01-21 00:32:35   收藏:0   阅读:366

将函数调用运算符“()”进行重载:

#include<iostream>
using namespace std;
class Add
{
	public:
		double operator ()(double a,double b);
};
double Add::operator() (double a,double b)
{
	return a+b;
}
int main()
{
	Add f;
	cout<<f(2.5,3.2)<<endl;
	return 0;
}

输出:5.7

原文:http://blog.csdn.net/qsyzb/article/details/18400905

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!