code_junkie

Overloads of inherited member functions

Nov 13th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include
  2. class Bound {
  3. public:
  4. Bound() : x0(0.0), x1(0.0) {};
  5. Bound(double x) : x0(x), x1(x) {};
  6. double width() const {return x1-x0;}
  7. void rebound(const Bound *a, const Bound *b);
  8. private:
  9. double x0, x1;
  10. };
  11.  
  12. void Bound::rebound(const Bound *a, const Bound *b)
  13. {
  14. if (a && b) {
  15. x0=std::min(a->x0, b->x0);
  16. x1=std::max(a->x1, b->x1);
  17. }
  18. }
  19.  
  20. class Node : public Bound {
  21. public:
  22. Node(double x) : Bound(x), left(0), right(0) {};
  23. Node(Node *a, Node *b) : left(a), right(b) {rebound();}
  24. void rebound() { rebound(left, right); }
  25. private:
  26. Node *left;
  27. Node *right;
  28. };
  29.  
  30.  
  31. int main() {
  32. Node A(1.0);
  33. Node B(2.0);
  34. Node C(&A, &B);
  35. }
  36.  
  37. using Bound::rebound;
  38. void rebound() { rebound(left, right); }
  39.  
  40. void rebound() { Bound::rebound(left, right); }
  41.  
  42. void rebound(const Bound *a, const Bound *b) { Bound::rebound(a, b); };
  43. void rebound() { rebound(left, right); }
Add Comment
Please, Sign In to add comment