Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 07.

Similar presentations


Presentation on theme: "CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 07."— Presentation transcript:

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 ?


Download ppt "CSE 2341 Honors Professor Mark Fontenot Southern Methodist University Note Set 07."

Similar presentations


Ads by Google