Saturday, February 23, 2013

OOCP (CPP) : Example # 10 : Inline Function Example using c++



OOCP (CPP)  :  Example #  10 : Inline Function Example using c++

* Lets start learning CPP (C++) Using Example.
* Constructor Example using c++.

//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
 10 : Inline Function Example using c++


/*
Inline 01

If function is called following activities carried out
- Jumping to the function
- Saving the register
-    Pushing the argument into stack.
- Return to the calling function

These activities can be avoided if we use inline....

Inline functin cannot work in following situation
- For function returning a value using If, Loop, Switch, goto
- For function not returning value and return statements are exist
- If function contains static variable
- if inline function is recursion
*/

#include <iostream.h>
#include <iomanip.h>
#include <conio.h>


class Digits
{
private:
long int n;
public:
Digits(long int pass)
{
n = pass;
}
inline int sum(long int m, int add);
void display(long int);
~Digits()
{
cout << "Destructor is called " << endl;
}
};

//=================================================
// Inline member function
//=================================================
int inline Digits :: sum(long int m, int add)
{
return(add + m%10);
}

//=================================================
//  Display member function
//=================================================
void Digits :: display(long int m)
{
cout << "Sum is : " << m << endl;
}

//=================================================
// Main Function
//=================================================
void main()
{
clrscr();
long int n;
int temp = 0;

cout << "Enter the long int no ";
cin >> n;

Digits d1(n);

while(n>0 || temp>9)
{
temp = d1.sum(n,temp);
n = n / 10;
d1.display(temp);

if(n==0 && temp > 9)
{
n = temp;
temp = 0;
}
} //while

getch();
} //void main


Output:
* Inline Function Example using c++.

--------------------------------------------------------------------------------
OOCP (CPP)  :  Example #  10 : Inline Function Example using c++

* Example demonstrate how to set function as inline function in c++.



Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

2 comments:

  1. Hello,
    I'm writing to ask a very basic question: anyone could give me some advices about the benefit of learning Java language.
    I've passed last year in exploring max and Jitter,
    and I've worked a lot on FFT and use of Jitter to handle FFT data. But I didn't dive to deeply in Jitter, because I'm not really interested in images. What I'd like to do is to have the possibility to make some operations on matrix based on Symmetry applications of Group Theory,
    In a way to modify the spectral informations held in the matrix. Someone could argue if this could be done in Max, or could be better to work on it learning JAva and programming specific Externals? For that I am trying to go for 6 week training http://www.wiziq.com/course/12145-the-6-week-complete-java-primer-with-training-certificate wonder this course
    will help me out
    Thanks.

    ReplyDelete
  2. Numerous individuals are at a misfortune with regards to dealing with their web journals and a gifted IT expert can help them drastically around there.information technology

    ReplyDelete