Home > DeveloperSection > Blogs > Inline Function in C++

Inline Function in C


.NET Visual C++ 
Ratings:
0 Comment(s)
 507  View(s)
Rate this:

Inline Function in C++

In this blog, I’m explaining about Inline function in C++

What is Inline function?

C++ provides an inline functions to reduce the function call overhead. Inline function is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted at the point of inline function call. This substitution is performed by the c++ compiler at compile time. Inline function may increase efficiency if it is small.

Example:

 

#include "stdafx.h"

#include <iostream>

using namespace std;

using namespace System;

inline double Max(double x,double y);

 public class InLineClass

{

public:

            double Max(double x,double y)

{

            return(x>y)?x:y;

}

 

int Max(int x,int y)

            {

            return(x>y)?x:y;

}

 };

 

 public class DriveClass:InLineClass

{

public:

           

 

 };

// Main function  for the program

int main(array<System::String ^> ^args)

{

            DriveClass DriveRef;

             InLineClass BaseRef

            double firstNum,SecNum,result;

            cout<<"Enter a number";

            cin>>firstNum;

            cout<<"Enter another number";

            cin>>SecNum;

            if(firstNum==SecNum)

            {

                        result=firstNum;

                        cout<<"Equal No.=";

            }

            else

            {

                        result= DriveRef.Max(firstNum,SecNum);// error

                        result= BaseRef.Max(firstNum,SecNum);//Right

            cout<<"Greater No.=";

 

            }

                        cout<<result;

            Console::ReadKey();

            return 0;

}

 

Note: Inline function cannot inherit in Drive class.


Don't want to miss updates? Please click the below button!

Follow MindStick