Defines constructor, destructor, and range() function in-line : inline « Class « C++ Tutorial






#include <iostream> 
using namespace std; 
 
class MyClass {  
  // These are now private. 
  int a; 
  int b;    
  int c;        
public: 
  // This is a constructor for MyClass. 
  MyClass(int p, int f, int m) { 
    a = p; 
    b = f; 
    c = m; 
  } 
 
  // Compute and return the range. 
  int range() { 
     return c * b; 
  } 
 
  // Accessor functions. 
  int getA() { return a; } 
  int getB() { return b; } 
  int getC() { return c; } 
}; 
 
int main() {  
  // Pass values to MyClass constructor. 
  MyClass myObject1(7, 16, 21);  
  MyClass myObject2(2, 14, 12); 
 
  int range1, range2;  
 
  range1 = myObject1.range(); 
  range2 = myObject2.range(); 
  
  cout << range1 << "\n";  
 
  cout << range2 << "\n";  
  
  return 0; 
}
336
168








9.24.inline
9.24.1.inline functions
9.24.2.inline function definiton
9.24.3.inline method
9.24.4.Automatic inline functions
9.24.5.Defines constructor, destructor, and range() function in-line
9.24.6.Using an inline function to calculate the volume of a cube.