Download presentation
Presentation is loading. Please wait.
Published bySolomon Kelly Modified over 9 years ago
1
CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 07
2
Class Details You can’t initialize data members in class interface class roster { private: int numStudents; int maxStudents = 30; char** names; public: roster(); //and so on }; Can’t do this.
3
Source Code Organization You have options – As you’ve been proceeding Interface:.h file Implementation:.cpp file Very common class roster { private: int numStudents; char ** names; public: roster(); }; roster::roster () { //constructor code } roster.h roster.cpp
4
Source Code Organization You have options – All in.h file but interface still separate from implementation class roster { private: int numStudents; char ** names; public: roster(); }; roster::roster() { //stuff } roster.h
5
Source Code Organization You have options – inline in the interface – method implementations actually appear in the class interface. class roster { private: int numStudents; char ** names; public: roster() { //constructor code here } int getNumStudents () { return numStudents; } }; roster.h
6
Constant Data Members and Initialization constant data members initialized using member initialization syntax class roster { private: int numStudents; const int maxStudents; char ** names; public: roster(int nums, int max); //and so on }; roster::roster(int nums, int max) { numStudents = nums; maxStudents = max; } What’s wrong here?
7
Constant Data Members and Initialization constant data members initialized using member initialization syntax class roster { private: int numStudents; const int maxStudents; char ** names; public: roster(int nums, int max); //and so on }; roster::roster(int nums, int max) : maxStudents(max) { numStudents = nums; maxStudents = max; } Executed before the object is fully created; const-ness has not attached yet to variables
8
Class Relationships Several types of relationships between two different classes Major types: – Composition one classis composed of other class objects and perhaps primitives – Inheritance one class inherits all of the data and functionality of another class
9
Composition An object can be made up of other objects class Computer { private: Motherboard mBoard; Processor proc; Ram ram; public: computer (); }; These aren’t primitives; they are object types
10
?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.