colin-benson
Uploaded by
13 SLIDES
265 VUES
130LIKES

C++ Week 6 Practice: Pointers, Static Members, Operator Overloading, and Inheritance

DESCRIPTION

This Week 6 C++ programming practice focuses on key concepts such as pointers and static members that are defined at the class level but applicable across instances. Explore operator overloading for input output operations and the distinction between base and derived class functions through method overriding. Learn about polymorphism with virtual functions and constructors, observing the creation chain from the base class to derived classes. Enhance your understanding of class relationships and the use of friend functions in C++.

1 / 13

Télécharger la présentation

C++ Week 6 Practice: Pointers, Static Members, Operator Overloading, and Inheritance

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++ Programming Practice Time Week 6.

  2. This • Pointer for current executing instance

  3. Practice : Static Member Member not on instance, but on definition Share-able in all instance of same class

  4. File Separate Implement Define

  5. Practice : Friend • Please Check Professor’s Material

  6. Practice : Operator Overloading • Overload • operator << (int Int_Val) {printf(“%d”, Int_Val;)} • operator << (const char* pCh) {printf(“%s”, pCh;)} • … • Override • Base Class function f_A • Derived Class function f_A • BaseClass *pBc = new DerivedClass(); • pBc->f_A(); //Derived Class function f_A will be called

  7. Inheritance • ex) • Room • Rm_Quiz, Rm_Dead, Rm_End

  8. Method Overriding

  9. Protected • Allowed • Inner • Derived Class • Denied • Outer • Derived’s Derived

  10. Constructor Chain • Base Class : Room • Derived Class : Rm_Dead • When Rm_Dead created. • 1) Room’s constructor called • 2) Rm_Dead’s constructor called • From Deep, To Shallow

  11. Polymorphism • Override • Base Class function f_A • Derived Class function f_A • BaseClass *pBc = new DerivedClass(); • pBc->f_A(); //Derived Class function f_A will be called • Type : BaseClass • Instance : DerivedClass

  12. Protected • Derived class will implement virtual function for its purpose

  13. The End of Week 6.

More Related