[WIP]C++ Objects Oriented
Created: 2021/08/11
Classes & Objects | |||||||||||||||||||||||||||||
class definition |
class sample { int a; // this scope is private public: ... };
|
||||||||||||||||||||||||||||
Inheritance | |||||||||||||||||||||||||||||
Base and Derived Classes |
class derived-class: access baseA, access baseB....
A derived class inherits all base class methods with the following exceptions
A derived class can access all the non-private members of its base class.
|
||||||||||||||||||||||||||||
Type of Inheritance |
We hardly use protected or private inheritance, but public inheritance is commonly used
|
||||||||||||||||||||||||||||
Overloading | |||||||||||||||||||||||||||||
C++ allows you 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. |
|||||||||||||||||||||||||||||
Function Overloading in C++ |
void sample(int a) {...} void sample(double a) {...}
|
||||||||||||||||||||||||||||
Operators Overloading in C++ |
Overloaded operators are functions with special names: the keyword "operator" followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list. Sample operator+(const Sample& right);
In case we define above function as non-member function of a class then we would have to pass two arguments for each operand as follows Sample operator+(const Sample& left, const Sample& right);
|
||||||||||||||||||||||||||||
Polymorphism | |||||||||||||||||||||||||||||
Abstraction | |||||||||||||||||||||||||||||
Encapsulation | |||||||||||||||||||||||||||||
Interfaces | |||||||||||||||||||||||||||||