Using inline rather than a macro. : define « Development « C++ Tutorial






#include <iostream>
using namespace std;
inline unsigned long Square(unsigned long a) { return a * a; }
inline unsigned long Cube(unsigned long a) 
    { return a * a * a; }
int main()
{
   unsigned long x=1 ;
   for (;;)
   {
      cout << "Enter a number (0 to quit): ";
      cin >> x;
      if (x == 0)
         break;
      cout << "You entered: " << x;
      cout << ".  Square(" << x << "): ";
      cout  << Square(x);
      cout<< ". Cube(" << x << "): ";
      cout << Cube(x) << "." << endl;
   }
   return 0;
}








5.16.define
5.16.1.ASSERTS
5.16.2.function macro of get the max value number
5.16.3.Using parentheses in macros.
5.16.4.Using inline rather than a macro.
5.16.5.A simple assert() macro.
5.16.6.Printing values in DEBUG mode