#pragma once /////////////////////////////////////////////////////////////////////// // Function Pointer - Demonstrate Function Pointers // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2017 // /////////////////////////////////////////////////////////////////////// #include #include // alias for pointer to global function using FPvv = void(*)(); // alias for pointer to global function with unspecified argument template using FPvp = void(*)(Param); // alias for pointer to gloabal function with argument and return value template using FPrp = Return(*)(Param); // global function void say() { std::cout << "\n my name is say"; } // global function with argument template void sayType(Param) { std::cout << "\n argument type is \"" << typeid(Param).name() << "\""; } // global function with argument and return value template Return same(Param) { if (typeid(Param).name() == typeid(Return).name()) { std::cout << "\n Param and Return are same type"; return true; } else { std::cout << "\n Param and Return are not same type"; return false; } } /////////////////////////////////////////////////////////////////////// // FunctionPointer class // - used to demonstrate member function pointers template class FunctionPointer { public: // alias's for member function pointers using FPvvm = void(FunctionPointer::*)(); using FPvpm = void(FunctionPointer::*)(Param); using FPrpm = Return(FunctionPointer::*)(Param); FunctionPointer(Param p) { p_ = p; } void say() { std::cout << "\n my name is \"" << "say" << "\""; } void sayType(Param) { std::cout << "\n argument type is \"" << typeid(Param).name() << "\""; } bool same(Param p) { return p == p_; } private: Param p_; };