Files Classes Functions Hierarchy
#include <cassert>#include <iostream>#include <vector>#include <fnobj.h>#include <fnobjT.h>#include <fnobjTfn.h>#include <print.h>#include <fnobjtest.h>
Go to the source code of this file.
Functions | |
| void | fnobjtest01 () |
| void | fnobjtest02 () |
| void fnobjtest01 | ( | ) |
Definition at line 40 of file fnobjtest.cpp.
Referenced by main().
00041 { 00042 hat h1; 00043 00044 cout << "Direct call to h1()" << endl; 00045 h1(); 00046 00047 cout << "call through functional pointer" << endl; 00048 00049 fnobj0T<hat&,void> h2(h1); 00050 fnobj0<void> *ptr; 00051 ptr = & h2; 00052 (*ptr)(); 00053 00054 cout << "member function hat3::sumfunc made into a functional object" << endl; 00055 00056 hat3 h3; 00057 //h3.sumfunc(); 00058 fnobj0Tfn<hat3,void> ph3(h3,&hat3::sumfunc); 00059 00060 ptr = &ph3; 00061 00062 (*ptr)(); 00063 00064 cout << "Testing the const functional ojbect" << endl; 00065 fnobj0const<void> *ptr2 = new hat2(); 00066 (*ptr2)(); 00067 00068 delete ptr2; 00069 00070 cout << "Testing const with a function func. object." << endl; 00071 00072 fnobj0constTfn<hat3,void> qh3(h3,&hat3::anotherone); 00073 ptr2 = &qh3; 00074 (*ptr2)(); 00075 }
| void fnobjtest02 | ( | ) |
Definition at line 126 of file fnobjtest.cpp.
References SHOW.
Referenced by main().
00127 { 00128 cout << "Demonstrating functional objects used to build a new type." << endl; 00129 cout << " people is a mixed type. This reminds me of Java interfaces" << endl; 00130 00131 vector< people* > v; 00132 00133 datamodel d1; 00134 d1.setAge2(15); 00135 00136 person p1; 00137 p1.setAge(20); 00138 00139 //new fnobj1Tfn<datamodel,void,int const>(d1,&datamodel::setAge2); 00140 00141 00142 v.push_back 00143 ( 00144 new people( 00145 new fnobj1Tfn<datamodel,void,int const>(d1,&datamodel::setAge2), 00146 new fnobj0constTfn<datamodel,int>(d1,&datamodel::getAge) 00147 ) 00148 ); 00149 00150 00151 v.push_back 00152 ( 00153 new people( 00154 new fnobj1Tfn<person,void,int const>(p1,&person::setAge), 00155 new fnobj0constTfn<person,int>(p1,&person::getthepersonsAge) 00156 ) 00157 ); 00158 00159 00160 00161 for (uint i=0; i<v.size(); ++i) 00162 cout << SHOW( v[i]->get() ) << endl; 00163 00164 for (uint i=0; i<v.size(); ++i) 00165 delete v[i]; 00166 }
1.5.8