Skip to content

Commit

Permalink
test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
realfirst committed May 1, 2011
1 parent dc8d06d commit 34b153a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ch21/pure_virtual_function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <cmath>
#include <iostream>

using namespace std;

class Function {
public:
// This is pure virtual
virtual double eval(double x) = 0;

// This calls the pure one
double derivative(double x, double e) {
return (eval(x+e) - eval(x-e))/(2*e);
}
};

class Oscillating : public Function {
public:
Oscillating(double aa, double bb, double cc)
:a(aa), b(bb), c(cc) {}
double eval(double x) {
return a*sin(b*x+c);
}
private:
double a, b, c;
};

int main(int argc, char **argv) {
Oscillating f(1, 1, 0);
cout << f.derivative(0, 0.1) << endl;
cout << f.derivative(0, 0.01) << endl;
cout << f.derivative(0, 0.001) << endl;
Function f1;
// let's mess the complier!
std::cout << f1.eval(3.0) << std::endl;
return 0;
}


1 change: 1 addition & 0 deletions test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ int main(int argc, char **argv) {
cout << "the patch test of git" << endl;

std::cout << "test of commit --amend" << std::endl;
std::cout << "show diff" << std::endl;
return 0;
}

0 comments on commit 34b153a

Please sign in to comment.