C++
Today Let's revise / refresh few aspects of C++ object oriented programming language
- A class has implicit members
- Default constructor
- Copy constructor. It cannot take object as argument. It always takes object reference as argument.
- Assignment operator
- Default destructor
- Now some specific points about constructor
- A class can have default constructor and explicit constructor. Explicit constructor force compiler for not to do implicit conversion
- However a constructor cannot be virtual
- The copy constructor is called in following cases
- If function return a object by value
- Function argument is object by value
- When we construct a object using another object
- Many times compiler generates temporary object
- Storage class
- auto
- register. Here '&' operator cannot be used
- static. The variable is initialize with value 0
- extern The variable is initialize with value 0
- Storage qualifier OR type qualifier
- volatile
- mutable
- restrict C99 standard. compiler optimization that avoid multiple loading of same variable.
- _Atomic . C99 standard
- const . In the context of pointer, const can be used 3 different ways
- int const * const x
- int const * x
- int * const x
- As we know for member function of class "this" pointer is passed by default. It is always passed as constant pointer.
- The following operator cannot be overloaded
- sizeof
- "."
- ".*"
- typeid
- "::"
- "?:"
- alignof
- .->
- Now about type casting of variables
- dynamic_cast . Runtime type check. It is used to case
- base class pointer to derived class pointer
- derive class pointer to another derive class pointer of same base class as parent.
- reinterpret_cast : cast to unrelated object
- static cast. compile time type check. for related object
- const_cast
- duration cast from chrono library
- C++ has specific features like
- Class
- Inline function
- Default argument
- Exception
- Namespace
- Boolean type
- Object Oriented Programming features
- Abstraction
- Encapsulation (information hiding)
- Inheritance
- Polymorphism
- Something about Inheritance
- Virtual inheritance is used to avoid diamond problem
- Inheritance applications are (1) code reuse and (2) overriding base class implementaiton
- 5 types of inheritance
- Single
- Multiple
- Multilevel
- Hierarchical
- Hybrid
- Something about polymorphism
- Static polymorphism
- Function overloading is also called ad-hoc polymorphism
- Templates is also called parametric polymorphism
- Dynamic polymorphism
- Subtyping is also called inclusion polymorphism
- C++ implements virtual table with single dispatch only. No multiple dispatch
0 comments:
Post a Comment