C++ is a high-level, general purpose object oriented programming language. It was created by Bjarne Stroustrup, a Danish computer scientist, as an extension of C programming language in early 80’s to add support of the Object Oriented Programming (OOP) features. Over time it has been extended to support wide range of programming features and abilities.
Stroustrup, during his PhD days, found the Simula‘s OOP features very useful for large scale software development. But Simula was very slow for most practical purposes. So, he created C++ adding the support of Simula‘s features in C. He chose C because it was fast, portable, general purpose and widely used programming language.
So, the primary motivation of C++ programming language was to support Object Oriented Programming features.
Object Oriented Programming (OOP)
Object Oriented Programming (OOP) is a programming paradigm around the concept of objects. An object contains data (also referred as properties or attributes) and methods (also referred as executions, functions or procedures).
In OOP, the real world entities are modelled as objects. Each object has its own data and access to the related functions. There could be different types of relationships among objects. Like, one object can be derived from another. Or, one object can contain other objects.
Overall, it is a different approach of solving real life problems over procedural programming.
Object Oriented Programming Features
- Class and Object: A class is kind of a blueprint that defines what features and functionalities the objects will have where the objects are the instances of the class. Together, they create the backbone of an object oriented programming. Read more.
- Inheritance: a mechanism of acquiring properties and behaviors in a class from another classes, also known as parent classes, to increase the code reusability. Read more.
- Polymorphism: the same piece of code behaves differently in different situations. The same interface, function or operation, is bound to different object types. Read more.
- Abstraction: a design concept of hiding data or implementation wherever possible and expose only the essential parts. Read more.
- Encapsulation: binding the related data and functions in a single entity, class. Read more.
Other Important C++ Features
- Function overloading: Multiple functions with the same name but different input parameters.
- Operator overloading: Giving meaning to an operator for user defined data types.
- Function overriding: Different implementations of a function in base and derived classes.
- Template function: Single function definition can be used for different data types.
- Template class: Single class definition can be used for different data types.
- Inline function: Executing the code of a function directly instead of transferring execution into the called function.
- Smart pointers: Managing the lifetime of an object automatically.
- Method chaining: Calling multiple methods (functions) in a single statement.
- Rvalue reference: One of the most significant features introduced in C++11 that enables move semantics and perfect forwarding.