标题总结了我的问题 - 我需要一个通用的 typedef 作为指向模板类方法的指针,如下面的代码所述。 typedef 需要是通用的。
template<typename TYPE>
struct MyClass {
const TYPE& get() const {}
};
// this is okay:
typedef void (MyClass<int>::*ParticleMethodPtr)( int );
// now I just need to typedef this so I can
// use the pointer on methods other than int
// using typedef, not okay:
template< TYPE >
typedef void (MyClass<TYPE>::*ParticleMethodPtr)( TYPE );
最佳答案
在 C++11 中:
template<typename TYPE>
using ParticleMethodPtr = const TYPE&(MyClass<TYPE>::*)() const;
ParticleMethodPtr<int> p = &MyClass<int>::get;
关于c++ - 指向模板类方法的指针的 Typedef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007153/