Procedural----- | member operator-----
[Link] on function not flow | An expression is a combination
[Link] moves openly | of variable, operands, and operators
OOPs----- | operations-------------
[Link] on class and objects | the keyword “operator” is used to define an overloaded operation.
Classes------ |The keyword “operator” is followed by the symbol of the operator being overloaded. The
Basic template for creating objects | signature of a member function that overloads an operator
Objects------ | included the keyword “operator,” the symbol, and the type of the
Basics run time entities. | right operand (if applicable) with in parentheses
Inheritance------ | The left operand of any member operator is always the current object Student
Properties of one class can be | [Link] data as critical objects|
Inherited into others. | Uranary and binary-------------
Polymorphism ------ | Unary: A unary operator or function operates on a single operand
Ability to take more then | A binary operator or function operates on two operands
One forms. Based on obj type | overloading not allowed-----------
BENEFIT oops------------ | for ::,dot, *. operator
Better reusability using obj, | code when we want to put the item to an empty state
Inheritance | m_itemName[0] == '\0' && m_price == 0
Help build secure sys.. | it should be equal to null terminator
employees = new Employee[noOfEmployees];|syntax-------
above is dynamic memory allocation example. ------------- |Accessing global scope
Constructor definition------------ |in member function
The member function automatically invokes when the | ::displayNo(); // calls the global function
Object of the class is created. | displayNo(); // calls the member function
| constructor syntax---------
Destrutor definition---special member function | Student::Student() {
no = 0;
ng = 0;
}
The special member function that every object invokes | default constructor syntax-------------
before going out of scope is called its class’s destructor. | Student::Student() {
An object’s destructor | // insert our terminal code here
Have no parameters or return values. Is called automatically| }
Cannot be overloaded Should not be called explicity | Use this when define in class------
Current object--------- | Student();
It needs a host object on which member function is called. |OPERATOR OVERLOADING SYNTAX
Definition------- | Student& operator=(const Student&);
The host object within a member function is referred to as |
the current object------------ |
The keyword this returns the address of the currentobject. |REFERENCE TO CURRENT OBJ.-----
this holds the address of the region of memory that | We can improve this definition of display()
contains all of the data stored in the instance variable. | by returning an unmodifiable reference
*this refers to the current object itself. | to the current object rather than a
Here use of allocation of memory | copy of the object.
#include<iostream> |Pre fix operator----
using namespace std; |Type& operator++() or Type& operator--()
void main() { |example backup = ++harry;
int* ptr; |because increment value by 1
ptr = new int[3]; | COPY CONSTRUCTOR
for (int i = 0; i < 3; i++) { | The copy constructor contains
cin >> *ptr; | the logic for copying from a source object
ptr = ptr + 1; | to a newly created object of the same type
} | The compiler calls this constructor when the client code
cout << "Values in array "; | 1. Create an objects by initializing it to the
for (int i = 0; i < 3; i++) { | existing object
cout << *ptr << "\t"; | 2. Copies an object by value in function call
ptr = ptr + 1; | [Link] an object by value from a function
} || Declaration
} | type(const type&)
Deallocate memory |Inheritance relate to classes?
void deallocateMemory() { |Share the same struct, allow one class to inherit
for (int i = 0; i < noOfEmployees; i++) { | the struct of another class.
delete[] employees[i].m_name; | polymorphism help in minimizing code dupli.?
} |different implementations based on the object type
delete[] employees; } |within the same inheritance hierarchy.
SUMMARY OF CURRENT OBJECT.
the current object is the current host object for the member function
a member function's parameters consist of implicit and explicit parameters
a member function's explicit parameters receive information from the client code
a member function's implicit parameters bind the function to the instance variables of current object
the keyword this holds the address of the current object
*this refers to the current object itself
the keyword this is meaningless outside a member function
POSTFIX OPERATOR
We overload the post-fix operators to increment/decrement the current object after returning its value.
The header for a post-fix operator takes the form
return_type operator++(int) or Type operator--(int)
BOOL OPERATOR
operator bool() const;
INTI FUNCTION WORKSHOP 3
void Bill::init(const char* title, int noOfItems | trncpy(m_title, title, 36); _items = new Item[m_noOfItems]; }
{ m_title[36] = '\0'; for (int i = 0; i < noOfItems; ++i) }
m_itemsAdded = 0; { else{
if (title != nullptr && noOfItems > 0) m_noOfItems = noOfItems m_items[i].setEmpty(); setempty() }