Using Polymorphic Classes

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

TestFunctions.C
#include <iostream>
#include "Sinus.h"
#include "Cosinus.h"
#include "FunctionRegistry.h"

using namespace std;

int main() {
   FunctionRegistry registry;
   registry.add(new Sinus());
   registry.add(new Cosinus());

   string fname; double x;

   while (cout << ": " &&
          cin >> fname >> x) {
      if (registry.is_known(fname)) {
         Function* f(registry.get_function(fname));
         cout << f->execute(x) << endl;
      } else {
         cout << "Unknown function name: " << fname << endl;
      }
   }
} // main

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 21, 2002