User Tools

Site Tools


cs509:cplusplus_inline_functions

Example: C++ inline functions

// Using an inline function to calculate
// the volume of a cube

#include<iostream>

using namespace std;

inline double cube( const double s ) { return s * s * s; }

int main()
{
   double side;
   
   cout << "\n Enter the side length of your cube: ";
   
   cin >> side;

   cout << "\n Volume of cube with side "
        << side << " is " << cube( side ) << endl;


   // inline function, cube(), would be inserted here
   // like this:
   // 
   //    const double s = side;
   //    cout << "\n Volume of cube with side "
   //         << side << " is " << s * s * s << endl;
   

   return 0;
}
cs509/cplusplus_inline_functions.txt · Last modified: 2013/03/06 18:56 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki