[C++] c++ 使用内联而不是宏 →→→→→进入此内容的聊天室

来自 , 2021-04-04, 写在 C++, 查看 131 次.
URL http://www.code666.cn/view/49ad23d1
  1. // 使用内联而不是宏
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. inline unsigned long Square(unsigned long a) {
  6.         return a * a;
  7. }
  8. inline unsigned long Cube(unsigned long a) {
  9.         return a * a * a;
  10. }
  11.  
  12. int main() {
  13.         unsigned long x = 1;
  14.         for (;;) {
  15.                 cout << "Enter a number (0 to quit): ";
  16.                 cin >> x;
  17.                 if (x == 0)
  18.                         break;
  19.                 cout << "You entered: " << x;
  20.                 cout << ". Square(" << x << "): ";
  21.                 cout << Square(x);
  22.                 cout << ". Cube(" << x << "): ";
  23.                 cout << Cube(x) << "." << endl;
  24.         }
  25.         return 0;
  26. }
  27.  

回复 "c++ 使用内联而不是宏"

这儿你可以回复上面这条便签

captcha