Friend Exceptions and More Friend classes Friend class
![Friend, Exceptions, and More • • Friend classes Friend class methods Nested classes Throwing Friend, Exceptions, and More • • Friend classes Friend class methods Nested classes Throwing](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-1.jpg)
![Friends • Friend function – Allow to access the private and protected members of Friends • Friend function – Allow to access the private and protected members of](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-2.jpg)
![Friend class • TV and Remote – On/off – Channel setting – Volume setting Friend class • TV and Remote – On/off – Channel setting – Volume setting](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-3.jpg)
![Friend member functions Friend member functions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-4.jpg)
![Friend relationships • Program tvfm. h Friend relationships • Program tvfm. h](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-5.jpg)
![Interactive remote controller Interactive remote controller](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-6.jpg)
![Shared friends • Probe class – Programmable measuring device • Analyzer class – Programmable Shared friends • Probe class – Programmable measuring device • Analyzer class – Programmable](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-7.jpg)
![Shared friends Shared friends](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-8.jpg)
![Nested classes Suppose queue class declaration: Nested classes Suppose queue class declaration:](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-9.jpg)
![Methods definitions Methods definitions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-10.jpg)
![More appropriate declaration More appropriate declaration](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-11.jpg)
![Using constructor to rewrite This makes the code for enqueuer() a bit shorter and Using constructor to rewrite This makes the code for enqueuer() a bit shorter and](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-12.jpg)
![Nested classes and access • Nested class is different from containment • A nested Nested classes and access • Nested class is different from containment • A nested](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-13.jpg)
![Scope properties for nested classes 二類別 • Program queuetp. h, nested. cpp Scope properties for nested classes 二類別 • Program queuetp. h, nested. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-14.jpg)
![Exceptions • Standard error stream – abort(); // cstdlib. h, doesn’t clear buffer – Exceptions • Standard error stream – abort(); // cstdlib. h, doesn’t clear buffer –](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-15.jpg)
![The exception mechanism • Three components – Throwing an exception (throw) – Catching an The exception mechanism • Three components – Throwing an exception (throw) – Catching an](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-16.jpg)
![Program flow with exceptions Program flow with exceptions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-17.jpg)
![Using objects as exceptions • Program exc_mean. h, error 4. cpp Using objects as exceptions • Program exc_mean. h, error 4. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-18.jpg)
![Unwinding the stack • Program error 5. cpp Unwinding the stack • Program error 5. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-19.jpg)
![More exception features More exception features](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-20.jpg)
![](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-21.jpg)
![catch (…) catch (…)](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-22.jpg)
![The exception class The exception class](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-23.jpg)
![The stdexception class • Classes logic_error, runtime_error derived publicly from exception • Classes domain_error, The stdexception class • Classes logic_error, runtime_error derived publicly from exception • Classes domain_error,](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-24.jpg)
![The logic_error class The logic_error class](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-25.jpg)
![The bad_alloc exception and new • Class bad_alloc derived publicly from exception class • The bad_alloc exception and new • Class bad_alloc derived publicly from exception class •](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-26.jpg)
![Exceptions, classes, and inheritance • One can derive one exception class from another • Exceptions, classes, and inheritance • One can derive one exception class from another •](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-27.jpg)
![Runtime type identification (RTTI) • RTTI is one of more recent additions to C++, Runtime type identification (RTTI) • RTTI is one of more recent additions to C++,](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-28.jpg)
![How does RTTI work? • Three components supporting RTTI • dynamic_cast operator – Generate How does RTTI work? • Three components supporting RTTI • dynamic_cast operator – Generate](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-29.jpg)
![dynamic_cast operator dynamic_cast operator](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-30.jpg)
![• Program rtti 1. cpp • Program rtti 1. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-31.jpg)
![The typeid operator & type_info class • #include <typeinfo. h> if (typeid(Magnificent) == typeid(*pg)) The typeid operator & type_info class • #include <typeinfo. h> if (typeid(Magnificent) == typeid(*pg))](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-32.jpg)
![Misusing RTTI Rewrite code Misusing RTTI Rewrite code](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-33.jpg)
![Type cast operators Type cast operators](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-34.jpg)
![Completing type cast • • dynamic_cast const_cast static_cast reinterpret_cast Completing type cast • • dynamic_cast const_cast static_cast reinterpret_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-35.jpg)
![dynamic_cast dynamic_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-36.jpg)
![const_cast • Program constcast. cpp const_cast • Program constcast. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-37.jpg)
![static_cast static_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-38.jpg)
![reinterpret_cast • The following type cast is allowed in C but not in C++ reinterpret_cast • The following type cast is allowed in C but not in C++](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-39.jpg)
- Slides: 39
![Friend Exceptions and More Friend classes Friend class methods Nested classes Throwing Friend, Exceptions, and More • • Friend classes Friend class methods Nested classes Throwing](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-1.jpg)
Friend, Exceptions, and More • • Friend classes Friend class methods Nested classes Throwing exceptions, try blocks and catch blocks Exception classes Runtime type identification (RTTI) dynamic_cast and typeid static_cast, const_cast, and reinterpret_cast
![Friends Friend function Allow to access the private and protected members of Friends • Friend function – Allow to access the private and protected members of](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-2.jpg)
Friends • Friend function – Allow to access the private and protected members of the original class • Friend class – Every member function in the friend class are allowed to access both private and protected members of the original class
![Friend class TV and Remote Onoff Channel setting Volume setting Friend class • TV and Remote – On/off – Channel setting – Volume setting](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-3.jpg)
Friend class • TV and Remote – On/off – Channel setting – Volume setting – Antenna or cable tuning mode – TV tuner or A/V input • Program tv. h, tv. cpp, use_tv. cpp
![Friend member functions Friend member functions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-4.jpg)
Friend member functions
![Friend relationships Program tvfm h Friend relationships • Program tvfm. h](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-5.jpg)
Friend relationships • Program tvfm. h
![Interactive remote controller Interactive remote controller](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-6.jpg)
Interactive remote controller
![Shared friends Probe class Programmable measuring device Analyzer class Programmable Shared friends • Probe class – Programmable measuring device • Analyzer class – Programmable](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-7.jpg)
Shared friends • Probe class – Programmable measuring device • Analyzer class – Programmable analyzing device • Each has an internal clock and one would like to be able to synchronize the two clocks
![Shared friends Shared friends](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-8.jpg)
Shared friends
![Nested classes Suppose queue class declaration Nested classes Suppose queue class declaration:](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-9.jpg)
Nested classes Suppose queue class declaration:
![Methods definitions Methods definitions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-10.jpg)
Methods definitions
![More appropriate declaration More appropriate declaration](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-11.jpg)
More appropriate declaration
![Using constructor to rewrite This makes the code for enqueuer a bit shorter and Using constructor to rewrite This makes the code for enqueuer() a bit shorter and](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-12.jpg)
Using constructor to rewrite This makes the code for enqueuer() a bit shorter and a bit safer because it automates initialization rather than requiring the programmer to correctly remember what should be done
![Nested classes and access Nested class is different from containment A nested Nested classes and access • Nested class is different from containment • A nested](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-13.jpg)
Nested classes and access • Nested class is different from containment • A nested class is declared controls the scope of the nested class. It establishes which parts of a program can create objects of that class • Nested class object can be used in class A • As with an class, the public, protected, and private sections of a nested class provide access control to class members
![Scope properties for nested classes 二類別 Program queuetp h nested cpp Scope properties for nested classes 二類別 • Program queuetp. h, nested. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-14.jpg)
Scope properties for nested classes 二類別 • Program queuetp. h, nested. cpp
![Exceptions Standard error stream abort cstdlib h doesnt clear buffer Exceptions • Standard error stream – abort(); // cstdlib. h, doesn’t clear buffer –](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-15.jpg)
Exceptions • Standard error stream – abort(); // cstdlib. h, doesn’t clear buffer – cerr(); // standard error stream – exit(); // clear buffer, but no messages • Program error 1. cpp, error 2. cpp
![The exception mechanism Three components Throwing an exception throw Catching an The exception mechanism • Three components – Throwing an exception (throw) – Catching an](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-16.jpg)
The exception mechanism • Three components – Throwing an exception (throw) – Catching an exception with a handler (catch) – Using a try block (try) • Program error 3. cpp
![Program flow with exceptions Program flow with exceptions](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-17.jpg)
Program flow with exceptions
![Using objects as exceptions Program excmean h error 4 cpp Using objects as exceptions • Program exc_mean. h, error 4. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-18.jpg)
Using objects as exceptions • Program exc_mean. h, error 4. cpp
![Unwinding the stack Program error 5 cpp Unwinding the stack • Program error 5. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-19.jpg)
Unwinding the stack • Program error 5. cpp
![More exception features More exception features](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-20.jpg)
More exception features
![](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-21.jpg)
![catch catch (…)](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-22.jpg)
catch (…)
![The exception class The exception class](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-23.jpg)
The exception class
![The stdexception class Classes logicerror runtimeerror derived publicly from exception Classes domainerror The stdexception class • Classes logic_error, runtime_error derived publicly from exception • Classes domain_error,](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-24.jpg)
The stdexception class • Classes logic_error, runtime_error derived publicly from exception • Classes domain_error, invalid_argument, length_error, out_of_bounds derived publicly from logic_error • Classes range_error, overflow_error, underflow_error derived publicly from runtime_error
![The logicerror class The logic_error class](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-25.jpg)
The logic_error class
![The badalloc exception and new Class badalloc derived publicly from exception class The bad_alloc exception and new • Class bad_alloc derived publicly from exception class •](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-26.jpg)
The bad_alloc exception and new • Class bad_alloc derived publicly from exception class • Program newexcp. cpp • The null pointer and new
![Exceptions classes and inheritance One can derive one exception class from another Exceptions, classes, and inheritance • One can derive one exception class from another •](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-27.jpg)
Exceptions, classes, and inheritance • One can derive one exception class from another • One can incoporate exceptions into classes by nesting exception class declarations inside a class definition • Such nested declarations can be inherited and can serve as base classes themselves • Program sales. h, sales. cpp, use_sales. cpp
![Runtime type identification RTTI RTTI is one of more recent additions to C Runtime type identification (RTTI) • RTTI is one of more recent additions to C++,](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-28.jpg)
Runtime type identification (RTTI) • RTTI is one of more recent additions to C++, which is not supported by many older implementations • How can one tells what kind of object a base-class pointer points to? – Find the correct non-virtual functions in class – For the reasons of debugging
![How does RTTI work Three components supporting RTTI dynamiccast operator Generate How does RTTI work? • Three components supporting RTTI • dynamic_cast operator – Generate](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-29.jpg)
How does RTTI work? • Three components supporting RTTI • dynamic_cast operator – Generate a derived type from a pointer to a base type; return null pointer (0) when fail • typeid operator – Return a value identifying the exact type of an object • type_info structure – Store information about a particular type
![dynamiccast operator dynamic_cast operator](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-30.jpg)
dynamic_cast operator
![Program rtti 1 cpp • Program rtti 1. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-31.jpg)
• Program rtti 1. cpp
![The typeid operator typeinfo class include typeinfo h if typeidMagnificent typeidpg The typeid operator & type_info class • #include <typeinfo. h> if (typeid(Magnificent) == typeid(*pg))](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-32.jpg)
The typeid operator & type_info class • #include <typeinfo. h> if (typeid(Magnificent) == typeid(*pg)) … cout << “Now processing type “ << typeid(*pg). name() << endl; • Program rtti 2. cpp
![Misusing RTTI Rewrite code Misusing RTTI Rewrite code](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-33.jpg)
Misusing RTTI Rewrite code
![Type cast operators Type cast operators](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-34.jpg)
Type cast operators
![Completing type cast dynamiccast constcast staticcast reinterpretcast Completing type cast • • dynamic_cast const_cast static_cast reinterpret_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-35.jpg)
Completing type cast • • dynamic_cast const_cast static_cast reinterpret_cast
![dynamiccast dynamic_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-36.jpg)
dynamic_cast
![constcast Program constcast cpp const_cast • Program constcast. cpp](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-37.jpg)
const_cast • Program constcast. cpp
![staticcast static_cast](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-38.jpg)
static_cast
![reinterpretcast The following type cast is allowed in C but not in C reinterpret_cast • The following type cast is allowed in C but not in C++](https://slidetodoc.com/presentation_image_h/df052f1f803b6b0c72f6a99395976316/image-39.jpg)
reinterpret_cast • The following type cast is allowed in C but not in C++ implementations the char is too small to hold a pointer implementation
Lirik lagu more more more we praise you
More more more i want more more more more we praise you
Hello my friend friend of a friend
Hello my friend hello my future
Classe e subclasse dos determinantes
Pre ap classes vs regular classes
Busycomparative and superlative
Non predefined exceptions in oracle
Young superlative adjective
Comparatives safe
Classes with three or more grade levels are called
Human history becomes more and more a race
Spl exceptions
Apa itu robustness
Stark law exceptions
Present progressive exceptions
Php exceptions
Coccus
Koch's postulates exceptions
Pasteurization
Stark law exceptions
Ionization potential
Octet rule exceptions
Koch's postulates exceptions
It rolls downhill
Xnxn horse
Different types of exceptions in c++
Java exceptions list
What are question tags
Present continuous exceptions
Invoice exceptions
Hybridization exceptions
Pad see ew pronunciation
Exceptions imparfait
Whats imparfait
Exception of mendel's law
Cvc rule exceptions
Berry amendment
Tallcomparative and superlative
Gerondif exceptions