我刚开始学习c++。原谅这样的问题。我的任务是编写一个宏来计算周长并测试它。
#define _USE_MATH_DEFINES
#include <cmath>
#define LENGTH(radius) (2 * M_PI * radius)
float l1 = LENGTH(1 + 2); // The result should be 18.8495... I have 8.28. Incorrect result.
float l2 = 1 / LENGTH(2); // The result should be 0.07957... Working correctly.
我添加了额外的括号:
float l1 = LENGTH((1 + 2)); // Correct result.
如何在不添加额外括号的情况下编写这样的宏来获得正确的结果?