I have an unusual case of the error in the title, where std::assert gives the error but assert() from assert.h gives no error. This is g++ and the 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);
| ^~~~~~
It’s difficult to understand the origin of the error, since it’s defined like this.
# define assert(expr)
(static_cast <bool> (expr)
? void (0)
: __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION))
Source: Windows Questions C++