Create inline functions with inline keyword - C++ Class

C++ examples for Class:Member Function

Description

Create inline functions with inline keyword

Demo Code

#include <cstdlib> 
#include <iostream> 

using namespace std; 

class point /*w  ww .ja  v  a2s.  c  o  m*/
{ 
public : 
    point(); 
    void SetX(int xValue); 
    int GetX(void); 
    void SetY(int yValue); 
    int GetY(void); 

private: 
    int x ,y ; 
 }; 


 inline point ::point() 
 { 
    x = y = 0; 
 } 

 inline void point ::SetX(int xValue) 
 { 
    x = xValue; 
 } 

 inline int point ::GetX(void) 
 { 
    return (x ); 
 } 

 inline void point ::SetY(int yValue) 
 { 
    y = yValue; 
 } 

 inline int point ::GetY(void) 
  { 
    return (y ); 
 } 



 int main(int argc, char *argv []) 
 { 
     point rightHere; 

     rightHere.SetX(10); 
     rightHere.SetY(20); 

     cout << "(x ,y )=(" << rightHere.GetX(); 
     cout << "," << rightHere.GetY() << ")"; 
     cout << endl; 

     rightHere.SetX(20); 
     rightHere.SetY(10); 

     cout << "(x ,y )=(" << rightHere.GetX(); 
     cout << "," << rightHere.GetY() << ")"; 
     cout << endl; 

   
     return (0); 
 }

Result


Related Tutorials