Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ Programming CLASS This pointer Static Class Friend Class

Similar presentations


Presentation on theme: "C++ Programming CLASS This pointer Static Class Friend Class"— Presentation transcript:

1 C++ Programming CLASS This pointer Static Class Friend Class
Operator Overloading Inheritance

2 { this -> radius = radius; }
this-pointer this returns always a reference to the current object. Example: Circle::Circle(double radius) { this -> radius = radius; } radius of the current (new) object constructor’s argument 11/2014

3 this-pointer class AAA{ private: int a; char c; double d;
void set(AAA *pa) { cin >> pa -> a; cin >> pa -> c; cin >> pa -> d; class AAA{ private: int a; char c; double d; void set() //void set(AAA *this) { cin >> this -> a; cin >> this -> c; cin >> this -> d; 11/2014

4 [ practice 1 this pointer ]

5 [ practice 1 this pointer ]

6 [ practice 2 Static class ]
11/2014

7 A Class can declare other classes as "friend classes".
Friends A Class can declare other classes as "friend classes". A Class can declare external functions as "friends". friends can access private members and methods. 11/2014

8 friend int printfoo( foo &f1); };
Friend Declaration class foo { private: int i,j; friend class fee; friend int printfoo( foo &f1); }; 11/2014

9 [ practice 3 Friend ]

10 [ practice 3 Friend ]

11 for “standard” functions
Operator overloading Operator overloading for “standard” functions Like a normal function definition but with operator-binding syntax with the function name. E.g. + operator: <datatype> operator+ (double a, classA b) { … } 11/2014

12 [ practice 4 Operator overloading ]

13 You can create a new class that inherits from an existing class.
Inheritance You can create a new class that inherits from an existing class. The new class is a specialization of the existing class (called subclass). You can add new members and methods. You can replace methods. Motivation: Reuse of existing code 11/2014

14 Example: You have a class that represents “circles".
Inheritance Example: You have a class that represents “circles". Create a new class that represents “cylinders". Most of the behavior and attributes are the same, but a few are different/new (height of cylinder, different area computation, volume) 11/2014

15 A Cylinder is a extended (specialized) form of a Circle.
Inheritance Example A Cylinder is a extended (specialized) form of a Circle. height Circle Cylinder radius 11/2014

16 [ practice 5 inheritance ]

17 [ practice 5 inheritance…continue ]

18 [ practice 5 inheritance ]

19 Overloading vs Overriding
- allows creating several methods with the same name which differ from each other in the type of the input and the output of the function. Polymorphism way. Overriding - allows a child class to provide a specific implementation of a method that is already provided by one of its parent classes Overloading Overriding method name same type or number of parameter different return type same or different class C { public : void test(int a); void test(char b); } class D : public C { public : void test(int a); int test(int a); }

20 [ practice 6 method overriding (1/2) ]

21 [ practice 6 method overriding (2/2) ]

22 [ practice 6 method overriding ]

23 [ practice 7 Overriding & Overloading ]

24 [ explain 7 Overriding & Overloading ]

25 [ Exercise 1 Static & inheritance]
Super class: Person Sub class: Student 사람(학생) 수: Static data member

26


Download ppt "C++ Programming CLASS This pointer Static Class Friend Class"

Similar presentations


Ads by Google