home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 09 / bob / obj.bob < prev    next >
Text File  |  1991-07-10  |  2KB  |  101 lines

  1. class foo // the base class
  2. {
  3.   a,b;
  4.   static last;
  5.   static get_last();
  6. }
  7.  
  8. foo::foo(aa,bb)
  9. {
  10.   a = aa; b = bb;
  11.   return last = this;
  12. }
  13.  
  14. foo::get_last()
  15. {
  16.   return last;
  17. }
  18.  
  19. foo::set_a(aa)
  20. {
  21.   a = aa;
  22.   return this;
  23. }
  24.  
  25. foo::set_b(bb)
  26. {
  27.   b = bb;
  28.   return this;
  29. }
  30.  
  31. foo::count(; i)
  32. {
  33.   for (i = a; i <= b; ++i)
  34.     print(i,"\n");
  35.   return this;
  36. }
  37.  
  38. foo::get_a()
  39. {
  40.   return a;
  41. }
  42.  
  43. foo::get_b()
  44. {
  45.   return b;
  46. }
  47.  
  48. class bar : foo // a derived class
  49. {
  50.   c;
  51. }
  52.  
  53. bar::bar(aa,bb,cc)
  54. {
  55.   foo(aa,bb);
  56.   c = cc;
  57.   return this;
  58. }
  59.  
  60. bar::get_c()
  61. {
  62.   return c;
  63. }
  64.  
  65. bar::set_c(cc)
  66. {
  67.     c = cc;
  68.     return this;
  69. }
  70.  
  71. main(; cr,foo1,foo2,bar1,bar2)
  72. {
  73.     cr = "\n";
  74.     last = 99;
  75.     foo1 = new foo(1,2);
  76.     foo2 = new foo(11,22);
  77.     print("foo1=",foo1,cr);
  78.     print("foo2=",foo2,cr);
  79.     print("foo1->a=",foo1->get_a(),cr);
  80.     print("foo2->a=",foo2->get_a(),cr);
  81.     print("foo1->b=",foo1->get_b(),cr);
  82.     print("foo2->b=",foo2->get_b(),cr);
  83.     bar1 = new bar(111,222,333);
  84.     bar2 = new bar(1111,2222,3333);
  85.     print("bar1=",bar1,cr);
  86.     print("bar2=",bar2,cr);
  87.     print("bar1->a=",bar1->get_a(),cr);
  88.     print("bar1->b=",bar1->get_b(),cr);
  89.     print("bar1->c=",bar1->get_c(),cr);
  90.     print("bar2->a=",bar2->get_a(),cr);
  91.     print("bar2->b=",bar2->get_b(),cr);
  92.     print("bar2->c=",bar2->get_c(),cr);
  93.     print("Foo1 counting\n");
  94.     foo1->count();
  95.     print("Foo2 counting\n");
  96.     foo2->count();
  97.     print("last=",last,cr);
  98.     print("foo::last->a=",foo::get_last()->get_a(),cr);
  99.     print("bar::last->a=",bar::get_last()->get_a(),cr);
  100. }
  101.