/////////////////////////////////////////////////////////////// // templ1.cpp - demonstrating some unusual template defs // // // // Refer to Stroustrup, 13.2.3 - Template Parameters // // // // Jim Fawcett, CSE687 - Object Oriented Design, S'00 // /////////////////////////////////////////////////////////////// #include using namespace std; //----< declare two simple functions >------------------------------- void fun1() { cout << "\n this is fun1"; } void fun2() { cout << "\n this is fun2"; } //----< declare template class taking function pointer parameter >--- template class templ1 { string str; public: void show() { f(); } }; //----< declare strings with external linkage >---------------------- char *s1 = "first string"; char *s2 = "second string"; //----< declare template class taking pointer to string >------------ template class templ2 { public: void show() { cout << "\n " << (*s); } }; // //----< test unusual template definitions >-------------------------- void main() { cout << "\n Demonstrating use of templates with unusual parameters " << "\n ========================================================\n"; templ1 tl; tl.show(); templ1 t2; t2.show(); cout << '\n'; templ2<&s1> t3; t3.show(); templ2<&s2> t4; t4.show(); cout << "\n\n"; }