1 / 9

OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++

OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++. Karoly Bosa RISC SS2000. OVERVIEW: - Class definition - Object declaration - Inheritance - Virtual functions - Templates and Universal Quantification. 1. Class definition. C++: class Cell {

mei
Télécharger la présentation

OBJECT ORIENTED FEATURES AND IMPLEMENTATION OF UNIVERSAL QUANTIFICATION IN C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. 4. Virtual functions (Self Application Semantics) II. 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

  8. 5. Templates and Universal Quantification Simple Template: template<class T> class Vector { ...} Function Template: template<class T> void sort(Vector<T>& v) { unsigned int n = v.size(); for (int i=0; i<n-1; i++) for (int j=n-1; i<j; j--) if (v[j] < v[j-1]) { T temp = v[j]; v[j] = v[j-1]; v[j-1] = temp; } } Vector <int> vi; ... sort(vi); Vector<complex> vc; ... sort(vc); Universal Quantification: type Generic_sort = T.Generic_sortWRT[T] type Generic_sort[T] = {sort:(Vector[T] Vector[T]} value int_sort : Generic_sortWRT[int] = {sort=fun(v : Vector[int]) st(v);} In this case, the generic block contains only one function always.

  9. Thank You for your attention!

More Related