本文共 780 字,大约阅读时间需要 2 分钟。
轉載自
The first operator FontHandle() const { return f;}
The second FontHandle operator()() const { return f;}
The first, operator 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 second, operator()
, 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();
转载地址:http://yhsgi.baihongyu.com/