C | C++ |
|
|
A class is a user-defined datatype members and member functions and
is defined with the keyword class.
Objects are defined as an instance of a class. Once the object is created,
then it can operate on both data members and member functions.
Access modifiers are used to define accessibility for the class members.
It defines how the members of the class are accessed outside the class scope.
There are three types of access modifiers:
- Private
- Public
- Protected
- Object
- Class
- Inheritance
- Abstraction
- Encapsulation
- Polymorphism
An object is an instance of a class with the class's own methods or procedures
and data variables.
A class is a user-defined data type that we can use in our program, and it works
as an object constructor, or a "blueprint" for creating objects.
Inheritance is one of the main features of object-oriented programming in C++,
allowing us to inherit another class's properties.
Data abstraction refers to providing only essential information to the outside
world and hiding their background details.
Encapsulation is an Object Oriented Programming concept that binds together
the data and functions that manipulate the data, and that keeps both safe from
outside interference and misuse.
What is Polymorphism in C++? Polymorphism in C++ means, the same entity
(function or object) behaves differently in different scenarios.
Vectors are the same as dynamic arrays with the ability to resize itself automatically
when an element is inserted or deleted, with their storage being handled automatically
by the container.
Lists are sequence containers that allow non-contiguous memory allocation.
As compared to vector, the list has slow traversal, but once a position has been
found, insertion and deletion are quick.
Maps are associative containers that store elements in a mapped fashion.
Each element has a key value and a mapped value. No two mapped values
can have the same key values.
A constructor is a member function taht is invoked whenever we create an object,
it has the same name as that of the class.
There are 2 types of constructors:
- Default constructor
- Parameterized constructor
A destructor is a member function that is invoked automatically when the object goes out
of scope or is explicitly destroyed by a call to delete.
It's a type of polymorphism in which an operator is overloaded to give it the user-defined
meaning. C++ allows us to specify more than one definition for a function name or an operator
in the same scope, which is called function overloading and operator overloading, respectively.
A pointer is a variable that stores the memory address of another variable as its value.
Pointers are used extensively in both C and C++ for three main purposes: to allocate new
objects on the heap, to pass functions to other functions. to iterate over elements in arrays
or other data structures.
A reference variable is an alias, that is, another name for an already existing variable.
Once a reference is initialized with a variable, either the variable name or the reference
name may be used to refer to the variable.
References are used to refer an existing variable in another name whereas pointers
are used to store address of variable. References cannot have a null value assigned
but pointer can. A reference variable can be referenced by pass by value whereas a
pointer can be referenced by pass by reference.
An enumeration, or Enum , is a symbolic name for a set of values. Enumerations are
treated as data types, and you can use them to create sets of constants for use with
variables and properties.
Vector | List |
|
|
std::move is used to indicate that an object t may be "moved from", i.e. allowing the efficient transfer
of resources from t to another object.
constexpr indicates that the value, or return value, is constant and, where possible, is computed at compile time.