Download presentation
Presentation is loading. Please wait.
Published byAlban McBride Modified over 8 years ago
1
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
2
Contents A Problem to Solve Implementing a Solution Templates Inheritance Virtual Methods and Abstract Classes Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
3
A Problem to Solve Creating a video game with a group of classes to represent three types of boxes Plain box Toy box Magic box Begin by designing an ADT plain box Use aspects of its implementation for the other two boxes View header file, Listing C1-1Listing C1-1.htm code listing files must be in the same folder as the.ppt files for these links to work Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
4
Class Declarations Private Data Fields Constructors and Destructors Methods Accessor methods Mutator methods Passing parameters by constant reference. Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
5
Class Declarations Guidelines for safe and secure programming Declare data fields as private Declare as const any method that does not change the object Declare any parameter passed by reference as const Unless you are certain it must be modified by the method Preventing Compiler Errors Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
6
Implementing a Solution View Listing C1-2 Implementation file for the PlainBox classListing C1-2 Note a template version, Listing C1-3Listing C1-3 Implementation file for the PlainBox template class, Listing C1-4Listing C1-4 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
7
Inheritance Base Classes and Derived Classes View Listing C1-5, Template header fi le for the class ToyBoxListing C1-5 And the implementation file, Listing C1-6Listing C1-6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
8
Overriding Base-Class Methods Redefine inherited methods Example, Listing C1-7 Header file for the class MagicBoxListing C1-7 And the implementation, Listing C1-8Listing C1-8 Consider abstract class, an interface for the ADT Box, Listing C1-9 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
9
End Chapter C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.