打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c++ 中函数操作符operator() 的使用
userphoto

2018.05.26

关注
函数操作符:()
​可以实现将对象当函数来使用
​代码如下
/*func_operator.cpp*/
​  1 #include <iostream>
  2 using namespace std;
  3 class Square{
  4     public:
  5         double operator()(double x)const{
  6             return x*x;
  7
  8
  9         }
 10         int operator()(int a,int b,int c = 9){
 11             return a + b - c;
 12         }
 13
 14 };
 15 int main(void){
 16     Square square;
 17     cout << square(12.) << endl;  //144
 18     cout << square(10,20,30) << endl; //0
 19     cout << square(10,20) << endl; // 21
 20     return 0;
 21 }


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C++运算符重载(2)
请谨慎实现operator==操作符函数
使用lambda,远离bind
操作符优先级
第二题
c++学习笔记(九):运算符重载进阶
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服