软件设计课件:Lecture 06 C-plus-plus Classes.pptVIP

  • 0
  • 0
  • 约 65页
  • 2021-12-01 发布于安徽
  • 举报

软件设计课件:Lecture 06 C-plus-plus Classes.ppt

软件设计课件:Lecture 06 C-plus-plus Classes

Queue - a waiting line Used by computer systems internally We need programs that simulate queues Queue has well-understood behavior Enqueue - put things in a queue one at a time Dequeue - get those things back one at a time on demand Implementation hidden from clients Queue ADT - stable internal data structure Clients may not manipulate data structure directly Only queue member functions can access internal data Example: Queue Abstract Data Type Container classes (collection classes) Classes designed to hold collections of objects Services such as insertion, deletion, searching, sorting, or testing an item Examples: Arrays, stacks, queues, trees and linked lists Iterator objects (iterators) Object that returns the next item of a collection (or some action) Can have several iterators per container Book with multiple bookmarks Each iterator maintains its own “position” information Example: Container Iterator Design of a container a iterator Design of a container a iterator Thank you! * * * * 内置类型:int/char/float等基本类型 复合类型:数组/指针/引用等类型 * * * * * * * When using the Friend Only using the friend function for operator overloading! Never using the friend class. Outline Const friend this new/delete Static class members Encapsulation data abstraction this pointer (this指针指向调用该函数的对象) Allows objects to access their own address Not part of the object itself Implicit first argument on non-static member function call to the object (每个成员函数(除了static成员函数)都有一个额外的、隐含的形参this) 例: Class Test { public void func(int a) {}; }; Test test; test.func(1); 编译器会重写这个函数的调用:t.func(t, 1),即加上形参this Implicitly reference member data and functions This Cascaded member function calls Function returns a reference pointer to the same object {return *this;} Other functions can operate on that pointer Functions that do not return references must be called last This Example Member functions setHour, setMinute, and setSecond all return *this (reference to an object) For object t, conside

文档评论(0)

1亿VIP精品文档

相关文档