/////////////////////////////////////////////////////////////////// // weird.cpp - Solution of MT#1-Q4, MT#2-Q4, and MT#3-Q3 // // // // This is a demo showing how to create really weird expressions // // out of pointers to template functions. // /////////////////////////////////////////////////////////////////// #include template int b(){ return 2*i; } void a(int(*fptr)()) { std::cout << "\n value = " << fptr(); } // a typedef may make that easier to understand typedef int(*fptr)(); void another(fptr ptr) { std::cout << "\n another value = " << ptr(); } /////////////////////////////// // another scenario /////////////////////////////// class c { public: c(fptr ptr) {} }; int main() { a(b<1>); // returns 2 another(b<18>); // returns 18 c(b<1>); typedef int(*funPtr)(); funPtr fp[3] = { b<1>, b<2>, b<3> }; std::cout << "\n "; for(int i=0; i<3; ++i) std::cout << (fp[i]()); std::cout << "\n\n"; return 0; }