Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果有class T{ void M() };,我想要一个可以T::M用作模板参数的模板类。说这样的话:
class T{ void M() };
T::M
T t; TUser<T::M> user(t);
是否可以?
是的,有可能:
template< typename T, void (T::*M)() > struct something { void somewhere( T* obj ) { (obj->*M)(); } };
它的用法是这样的:
T t; something< T, &T::M > user; user.somewhere( &t );