Templates

Idea is to pass data type as a parameter so that we don’t need to write the same code for different data types.Templates are expanded at compiler time. This is like macros. The difference is, compiler does type checking before template expansion. Function templates Format - template <class identifier> function_declaration; or template <typename identifier> function_declaration;…

Functors

It is nothing but function object which can be treated as function using operator (). C++ allows operator() overloading. Functor object class overloads/defines its own operator () which allows the class object to be called as function itself. Example Functor creation and operator() overloading class sum { private: int num; public: sum(int n): num(n) {}…

Namespaces in C++

Name represents a entity.In a scope we can not have same name for two entity.Using namespace we use same name for different entities. Example How to declare namespace myspace { int var = 10; } int main(){ int var = 4; cout << var << endl; cout << myspace::var << endl; } We can create…