0% found this document useful (0 votes)
57 views8 pages

Object-Oriented Programming (OOP)

This document discusses object-oriented programming concepts including the this pointer, inline functions, and arrays of objects. [1] The this pointer points to the current object of a class and is used when a local variable name conflicts with a member name or to return a reference to the calling object. [2] Inline functions provide advantages like avoiding function call overhead but the compiler may ignore inline requests under certain conditions like loops or static/recursive functions. [3] Arrays can store objects by declaring the array type as the class and using the new operator to initialize each element with a constructor, or by directly initializing each element.

Uploaded by

Ahmed Ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views8 pages

Object-Oriented Programming (OOP)

This document discusses object-oriented programming concepts including the this pointer, inline functions, and arrays of objects. [1] The this pointer points to the current object of a class and is used when a local variable name conflicts with a member name or to return a reference to the calling object. [2] Inline functions provide advantages like avoiding function call overhead but the compiler may ignore inline requests under certain conditions like loops or static/recursive functions. [3] Arrays can store objects by declaring the array type as the class and using the new operator to initialize each element with a constructor, or by directly initializing each element.

Uploaded by

Ahmed Ashraf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Object-Oriented Programming

(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

1. Function call overhead doesn’t occur.


2. It also saves the overhead of push/pop variables on the stack when function is called.
3. It also saves overhead of a return call from a function.
4. When you inline a function, you may enable compiler to perform context specific
optimization on the body of function. Such optimizations are not possible for normal
function calls. Other optimizations can be obtained by considering the flows of
calling context and the called context.
5. Inline function may be useful (if it is small) for embedded systems because inline
can yield less code than the function call preamble and return.
Array of objects
books book[size] ;
for(int i=0; i<size; i++)
{
Rectangle *ptr_arr[2];
cout<<"Enter details of book "<<(i+1)<<"\n";
ptr_arr[0] = new Rectangle(10,20);
book[i].getdata(); ptr_arr[1] = new Rectangle(15,5);
}

//declaration array of objects


//with parameterized constructor
• Number N[3]={Number(10),Number(20),Number(30)};

You might also like