Presentation is loading. Please wait.

Presentation is loading. Please wait.

OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000.

Similar presentations


Presentation on theme: "OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000."— Presentation transcript:

1 OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000

2 OVERVIEW: - Class definition - Object declaration - Inheritance - Virtual functions - Templates and Universal Quantification

3 1. Class definition C++: class Cell { public : int contents; Cell() { contents=0; } int get() { return contents; } void set(int n) { contents = n; } } In the untyped  -calculus: Cell = [Cell =  (z)[contents =  (s)z.contents(s), get =  (s)z.get(s), set =  (s)z.set(s)], contents = (s) 0; get = (s) s.contents; set = (s) (n) s.contents:=n] When the constructor method is called, the system substitute class name Cell for self parameter Z.

4 2. Object declaration C++: Cell cellobject; The C++ call the constructor automatically. In the untyped  -calculus: cellobject = Cell.Cell = [contents =  (s) 0; get =  (s) s.contents; set =  (s) (n) s.contents:=n] When a method is called: cellobject.get()  s.contents {{s  cellobject}} = cellobject.contents;

5 3. Inheritance C++: class reCell : public Cell { public : int backup; reCell() { backup = 0; } void set(int n) { backup = contents; Cell::set(n); } void restore() { contents = backup;} } In the untyped  -calculus: reCell = [reCell =  (z)[contents =  (s)z.contents(s), get =  (s)z.get(s), set =  (s)z.set(s), backup =  (s)z.backup(s), restore =  (s)z.restore(s)], contents = Cell.contents, get = Cell.get, set = (s) (n) Cell.set(s.backup := s.contents)(n), backup = (s) 0; restore (s) s.contents := s.backup ]

6 4. Virtual functions (Self Application Semantics) I. C++ Example: class A{ public : void aa() { bb(); } virtual void bb() { cout << “Called: method bb of class A \n”; } } class B : public A { public: void bb() { cout << ”Called: method bb of class B \n”; } }... Declaration of objects: A objectA; B objectB; Self Application Semantics: objectA  [aa =  (x1){x1.bb}, bb =  (x2){cout <<...bb of A;}] When B extends A: A.bb()   (y){cout <<...bb of B;} objectB  [aa =  (x1){x1.bb}, bb =  (y){cout <<...bb of B;}] Question : if we call objectB.aa(), which method bb() will be done?

7 If we call objectA.aa()  x1.bb() {{x1  objectA}}  objectA.bb() then the output will be: Called: method bb of class A If we call objectB.aa()  x1.bb() {{x1  objectB}}  objectB.bb() then the output will be: Called: method bb of class B 4. Virtual functions (Self Application Semantics) II.

8 5. Templates and Universal Quantification Simple Template: template class Vector {...} Function Template: template void sort(Vector & v) { unsigned int n = v.size(); for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3277120/slides/slide_8.jpg", "name": "5.", "description": "Templates and Universal Quantification Simple Template: template class Vector {...} Function Template: template void sort(Vector & v) { unsigned int n = v.size(); for (int i=0; i

9 Thank You for your attention!


Download ppt "OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++ Karoly Bosa RISC SS2000."

Similar presentations


Ads by Google