this Pointer
Thethis 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
3.
1) When localvariable’s name is same
as member’s name
Inline Function
Aninline function is a function that is expanded in line when it is called.
6.
Inline Function
#include <iostream>
usingnamespace 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
7.
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.
8.
Inline functions providefollowing
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.
9.
Array of objects
booksbook[size] ;
for(int i=0; i<size; i++)
{
cout<<"Enter details of book "<<(i+1)<<"n";
book[i].getdata();
}
//declaration array of objects
//with parameterized constructor
Number N[3]={Number(10),Number(20),Number(30)};
Rectangle *ptr_arr[2];
ptr_arr[0] = new
Rectangle(10,20);
ptr_arr[1] = new Rectangle(15,5);