1 / 11

C++ support for Object-Oriented Programming

C++ support for Object-Oriented Programming. 程式設計 潘仁義 CCU COMM. “Donut” Model of Standard Type int. “Donut” Model of an Abstract Data Type. C does not allow to define operators Complex + Complex ? C permits only one meaning for a name abs( ), labs( ), llabs( ), fabs( ) ?.

pmarsh
Download Presentation

C++ support for Object-Oriented Programming

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. C++ support for Object-Oriented Programming 程式設計 潘仁義 CCU COMM

  2. “Donut” Model of Standard Type int

  3. “Donut” Model of an Abstract Data Type

  4. C does not allow to define operators Complex + Complex ? C permits only one meaning for a name abs( ), labs( ), llabs( ), fabs( ) ? C++ supports Class definition to group data structure and operations of an abstract data type supports operator overloading to include definitions of arithmetic and input/output operators supports function overloading Ex. Using only one “abs( )” Abstract Data Type supporting

  5. Comparison of Models of Standard Type int and Abstract Data Type Complex

  6. Header File for Class Complex • Complex comp1; • Complex comp2( 5.1 ); • Complex comp3( 9.1, -7.2);

  7. Implementation File for Class Complex • “this” • Member functions can access private data member • Member operators have direct access to the members of their first operand • If member function/operator does not change data members • Prototype ends in “const” • Why?

  8. Implementation File for Class Complex (cont’d) 有個bug, 猜猜在哪

  9. Driver Function to Test Class Complex

  10. Step-by-Step Evaluation of Multiple << Operations • ostream& operator<< (ostream& os, Complex c) {…os << fixed << showpoint << setprecision(2);…return os;}

  11. Q & A • Shadow copy vs. Deep copy • A shallow copy of an object copies all of the member field values • The default copy constructor and assignment operator make shallow copies • May not be what you want for fields that point to dynamically allocated memory • Deep copies need ... • Destructor • Copy constructor • Overloaded assignment operator

More Related