/* File: oop4main.cpp This example shows that callable objects can be compiled separately. The abstract base class Int2Int is defined in Int2Int.h The apply function is defined in apply.h and apply.cpp. These files can be compiled separately: g++ -c apply.cpp g++ -c oop4main.cpp g++ apply.o oop4main.o This means we can pass a function to apply that it has never seen before and have the intended effect. */ #include using namespace std ; #include "Int2Int.h" #include "apply.h" class IncX : public Int2Int { public: int operator()(int n) { return n+1 ; } } ; int main () { int B[10] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19} ; printf("Before:\n") ; for (int i=0 ; i < 10 ; i++) { cout << " B[" << i << "] = " << B[i] << endl ; } IncX finc ; apply (finc, B, 10) ; printf("\n\nAfter calling apply(finc, B, 10):\n") ; for (int i=0 ; i < 10 ; i++) { cout << " B[" << i << "] = " << B[i] << endl ; } }