///////////////////////////////////////////////////////////////// // invoker1.cpp - defines class to wrap function pointers // // Exam4:Q3 first solution // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 05 // ///////////////////////////////////////////////////////////////// #include #include template class delegate { public: virtual ~delegate() {} R operator()(A a) { return fptr(a); } }; int trunc(double d) { return static_cast(d); } struct Args { int i; double d; }; void simulateArgs(Args& a) { std::cout << "\n 1st arg = " << a.i; std::cout << "\n 2nd arg = " << a.d; } void main() { delegate del; int r = del(3.5); std::cout << "\n received " << del(3.5) << " from invoker\n\n"; delegate rdel; Args a = { -3, 3.1415927 }; rdel(a); std::cout << "\n\n"; }