Inline Functions in C++

Master C++ with Real-time Projects and Kickstart Your Career Start Now!!

Program 1

#include<iostream>
using namespace std;
class MyMath
{
      public:
      int square(int n)     //implicit / default inline
     {
           return n*n;
     }
};
// inline int MyMath::square(int n)  //defination
// {
//     return n*n;
// }
int main()
{
    system("cls");
    MyMath M;
    cout<<M.square(5);   //calling
    return 0;
}

// inline int square(int r)  //defination
// {
//     return r*r;
// }
// int main()
// {
//     system("cls");
//     cout<<endl<<square(5);  // calling   
//     cout<<endl<<square(8);  // calling   
//     cout<<endl<<square(4);  // calling   

//     return 0;
// }

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *