C++


Today Let's revise / refresh few aspects of C++ object oriented programming language


  • A class has implicit members
  1. Default constructor 
  2. Copy constructor. It cannot take object as argument. It always takes object reference as argument. 
  3. Assignment operator
  4. Default destructor 
  • Now some specific points about constructor
  1. A class can have default constructor and explicit constructor. Explicit constructor force compiler for not to do implicit conversion
  2. However a constructor cannot be virtual
  • The copy constructor is called in following cases
  1. If function return a object by value
  2. Function argument is object by value
  3. When we construct a object using another object
  4. Many times compiler generates temporary object
  • Storage class
  1. auto
  2. register. Here '&' operator cannot be used
  3. static. The variable is initialize with value 0
  4. extern The variable is initialize with value 0
  • Storage qualifier OR type qualifier
  1. volatile 
  2. mutable
  3. restrict C99 standard. compiler optimization that avoid multiple loading of same variable. 
  4. _Atomic . C99 standard 
  5. const . In the context of pointer, const can be used 3 different ways
    1. int const * const x
    2. int const * x
    3. 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 
  1. sizeof
  2. "."
  3. ".*"
  4. typeid
  5. "::"
  6. "?:"
  7. alignof
  8. .->
  • Now about type casting of variables 
  1. dynamic_cast . Runtime type check. It is used to case 
    1. base class pointer to derived class pointer
    2. derive class pointer to another derive class pointer of same base class as parent. 
  2. reinterpret_cast : cast to unrelated object
  3. static cast. compile time type check. for related object
  4. const_cast
  5. duration cast from chrono library
  • C++ has specific features like
  1. Class
  2. Inline function
  3. Default argument 
  4. Exception
  5. Namespace
  6. Boolean type
  • Object Oriented Programming features
  1. Abstraction
  2. Encapsulation (information hiding) 
  3. Inheritance 
  4. 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
We will some more topics about C++ and C programming language. Stay tunes

0 comments:

Post a Comment