64,282
社区成员
发帖
与我相关
我的任务
分享
template <typename>
struct proxy;
template <typename T, typename R, typename ...Args>
struct proxy<R (T::*)(Args...) const> {
typedef R (T::*func_t)(args...);
func_t _func;
proxy(func_t f) : _func(f) {}
R call(const T*obj, Args&&...args) {
_func(obj, std::forward<Args>(args)...);
}
};
我随便写的不一定能编译过。c++11的代码。
那个函数尾的const,代表this是const this。由于this和const this是不同的参数,所以在编译级可以重载。
virtual const函数的还是挺有必要的。父类不希望子类改变它的关键数据。当然了,这里缺乏个粒度,子类想改变只是属于自己的数据。