“错误:在 std::assert 上的‘’标记”之前预期不合格的 id

问题描述

我在标题中有一个不寻常的错误案例,其中 std::assert 给出了错误,但 assert.h 中的 assert() 没有给出错误。这是 g++ 和 GNU libstdc++。

void HealthMembership::calculateCharges(void)
{
    float fee;
    
    std::assert(this->fee_type);
    fee = this->in_months * this->fee_rates[this->fee_type];
    std::cout << std::fixed << std::showpoint << std::setprecision(2);
    std::cout << "The total charges are $" << fee << '\n';
}
Q8.cxx:37:7: error: expected unqualified-id before ‘(’ token
   37 |  std::assert(fee_type);
      |       ^~~~~~

很难理解错误的根源,因为它是这样定义的。

#  define assert(expr)                          \
     (static_cast <bool> (expr)                     \
      ? void (0)                            \
      : __assert_fail (#expr,__FILE__,__LINE__,__ASSERT_FUNCTION))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)