Create an inline function. : inline « Class « C++






Create an inline function.

Create an inline function.
 
#include <iostream>
using namespace std;

class myclass {
  int a, b;
public:
  void init(int i, int j);
  void show();
};

// an inline function.
inline void myclass::init(int i, int j)
{
  a = i;
  b = j;
}

// another inline function.
inline void myclass::show()
{
  cout << a << " " << b << endl;
}

int main()
{
  myclass x;

  x.init(10, 20);
  x.show();

  return 0;
}


           
         
  








Related examples in the same category

1.Inline functions may be class member functionsInline functions may be class member functions
2.Automatic inlineAutomatic inline
3.Use inline to make this program more efficient
4.Creating Inline Functions Inside a Class
5.Inline function that calculates the volume of a sphere