یک نمونه از تابع inline
یک شنبه 7 آذر 1389 12:20 AM
1 Using an inline function to calculate the volume of a cube.محاسبه حجم مکعب
2 #include <iostream>
3 using std::cout;
4 using std::cin;
5 using std::endl;
6
7 // Definition of inline function cube. Definition of function appears
8 // before function is called, so a function prototype is not required.
9 // First line of function definition acts as the prototype.
10 inline double cube( const double side )
11 {
12 return side * side * side; // calculate cube
13 } // end function cube
14
15 int main()
16 {
17 double sideValue; // stores value entered by user
18 cout << "Enter the side length of your cube: ";
19 cin >> sideValue; // read value from user
20
21 // calculate cube of sideValue and display result
22 cout << "Volume of cube with side "
23 << sideValue << " is " << cube( sideValue ) << endl;
24 return 0; // indicates successful termination
25 } // end main