Here is one example where use of member function pointer - within a class, as an implementation detail - is perfectly acceptable, if one works with performance-sensitive code for different CPU architectures.
See the C++ FAQs for the proper use of member function pointer. It requires a different syntax than static function pointers.
(Thanks for Kaz for the suggestion.)
class SomePerformanceCriticalOperation
{
private:
// the type declaration of a member function pointer
typedef int (SomePerformanceCriticalOperation::*ProcessPtr)(size_t bytesToProcess, void* dataPtr);
// the instance of a member function pointer, to be assigned to a member function
// (inside the constructor)
ProcessPtr m_ptr;
public:
SomePerformanceCriticalOperation()
{
cpu_features feat = ::GetCpuFeatures();
if (TestBit(feat, cpu_features_SSE41))
m_ptr = &SomePerformanceCriticalOperation::Process_SSE41;
else if (TestBit(feat, cpu_features_SSSE3))
m_ptr = &SomePerformanceCriticalOperation::Process_SSSE3;
else if (TestBit(feat, cpu_features_SSE3))
m_ptr = &SomePerformanceCriticalOperation::Process_SSE3;
else if (TestBit(feat, cpu_features_SSE2))
m_ptr = &SomePerformanceCriticalOperation::Process_SSE2;
else if (TestBit(feat, cpu_features_MMX))
m_ptr = &SomePerformanceCriticalOperation::Process_MMX;
else
m_ptr = &SomePerformanceCriticalOperation::Process_CPlusPlus;
}
// The CPU-specific functions, as usual. (Omitted.)
int Process_SSE41(size_t bytesToProcess, void* dataPtr) { ... }
};
std::function
(in the<functional>
header)?