Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)
(OOP)
Week – 05
Feb 17-21, 2019
Instructor: Basit Ali
Email: [email protected]
Object-Oriented Programming (OOP)
this Pointer
• The this pointer holds the address of current object, in simple
words you can say that this pointer points to the current
object of the class.
Use?
1. When local variable’s name is same as member’s name
2. To return reference to the calling object
1) When local variable’s name is same as
member’s name
2) To return reference to the calling object
Inline Function
#include <iostream>
using namespace std;
inline int cube(int s)
{
return s*s*s;
}
int main()
{
cout << "The cube of 3 is: " << cube(3) << "\n";
return 0;
} //Output: The cube of 3 is: 27
Inline Function
• Remember, inlining is only a request to the compiler, not a command. Compiler can ignore
the request for inlining. Compiler may not perform inlining in such circumstances like:
1) If a function contains a loop. (for, while, do-while)
2) If a function contains static variables.
3) If a function is recursive.
4) If a function return type is other than void, and the return statement doesn’t exist in
function body.
5) If a function contains switch or goto statement.
Inline functions provide following advantages