无法解析函数"assert"

Function "assert" could not be resolved

本文关键字:assert 函数      更新时间:2023-10-16

我正在尝试编写一个简单的代码来测试"创建函数",但是当我使用assert时出现此错误:无法解析函数断言。

这是我的代码:

#include "Participant.h"
#include "ParticipantValidator.h"
#include <assert.h>
void testCreateParticipant()
{
    Participant part(1, "Corina", "Marin", 5);
    assert(part.getId() == 1);
    assert(part.getScore() == 5);
    assert(part.getName() == "Corina");
    assert(part.getFamilyName() == "Marin");
}

没有函数assert()。它是一个宏。您可能包含了错误的 assert.h 版本,或者在您之前包含的某个文件中有一个在 assert.h 中被评估为包含保护的#define

  • 检查您真正包含的包含文件(包括 absulote 路径)。
  • 尝试在没有其他头文件的情况下在示例中使用 assert

在C++中,你应该#include <cassert>而不是#include <assert.h>