我写了以下函数:
template< class C, typename T, typename U >
void addVarCB(C * _this, const std::string &name,
T(C::*getter)(void) const, U(C::*setter)(const T&), const std::string &def);
然后我意识到如果 setter 将 T 作为输入,它将不起作用,所以我重载了该函数:
template< class C, typename T, typename U >
void addVarCB(C * _this, const std::string &name,
T(C::*getter)(void) const, U(C::*setter)(T), const std::string &def = "");
现在我意识到,如果吸气剂返回,即使这样也会失败
const T &
T &
const T *
T *
const T // yeah this is dumb but someone on my team wrote code like this...
我注定要到处复制相同的代码吗?希望至少解决方案仅适用于参考版本?
请注意,该函数采用指向对象的 this 指针、getter 和 setter 公共成员函数。然后,该函数将与 GUI 接口,允许稍后回调 getter 和 setter。