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

轉載自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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值