Effective c++ 3/e item 15 疑問解惑

c++ 专栏收录该内容
36 篇文章 0 订阅

轉載自http://stackoverflow.com/questions/4728160/thrown-off-by-functor-syntax-in-effective-c

The first

operator
FontHandle() const {return f;}
The second

FontHandle operator()() const {return f;}

The firstoperator FontHandle, is a conversion operator. It allows an instance of this class type to be implicitly converted to a FontHandle object, so you could write:

Font myFont; FontHandle handle = myFont;

More commonly, conversion operators are used to allow you to use an object of one type as if it were another type in an expression. For example,

void f(FontHandle fh); Font myFont; f(myFont); // converts myFont to a FontHandle via the conversion operator
 

The secondoperator(), is an overload of the function call operator. It allows an instance of your class type to be used as if it were a function taking no arguments:

Font myFont; myFont();
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值