取 operator<< 之类的运算符重载函数的地址
重载运算符其实也是定义一个函数,只是这个函数有点隐晦。首先我们要面对的就是运算符被重载得太多,必须要有办法区别类型,此时用模板最好了。
template <typename fun_type>
fun_type addr_fun(fun_type a)
{ return a; }
使用:
typedef ostream& out_type(ostream&, int); // ostream& operator << (ostream&, int)
addr_fun<out_type>(operator <<);
事实上,有更简单的办法:
out_type f = operator <<;
这些方法,对普通的重载的函数同样使用。