Ahmad

Ahmad

#112 – Enforcing encapsulation in C++

Introduction Encapsulation is a technique used to enforce the separation of interface and implementation by hiding (making inaccessible) the implementation of a program-defined data type from users. We use access specifiers to achieve this objective. Consider a classic OOP-based class…

#108 – Crash course on std::pair

Sometimes a function or container needs to keep two related values together. You could write your own small struct, but there’s no need to reinvent the wheel. C++ already provides a simple standard option: std::pair. It is a class template from <utility> that…

#107 – Introduction to class templates

Examine the program below: We have to duplicate the struct and function just to support another type. What if we want the program to be compatible with more types like float? Clearly this doesn’t scale. We can do better. Class…