// B2.9.cpp : Defines the entry point for the console application. // // Please provide the definition of a template-based class that provides // a function object that returns a string representing the type of the // object that invoked it and the type of the template parameter. // Show how a client will use this function. #include "stdafx.h" #include #include using namespace std; template class functor { public: std::string operator()() { string types = " invoker type: "; types += typeid(*this).name(); types += "\n template parameter type: "; types += typeid(T).name(); return types; } }; int _tmain(int argc, _TCHAR* argv[]) { std::cout << "\n Exam B2 - Question #9 " << "\n =======================\n"; // functor style of invocation functor myTypes; cout << myTypes().c_str(); cout << "\n\n"; // alternate way of invoking that shows invoker more clearly cout << (myTypes.operator()()).c_str(); cout << "\n\n"; return 0; }