2014-04-06 58 views
0

我正在尝试编写一个简单的代码来测试“创建函数”,但是当我使用assert时出现此错误:函数assert无法解析。函数“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"); 
} 
+0

为什么不使用单元测试框架 - 即boost_unit或CPP单元例如 –

+0

@EdHeal:也许是因为断言不只是为了测试,但也是在产品构建有用。 –

+1

@ user3316022:尝试通过在自包含的,编译的示例再现错误的错误隔离。如果Participant.h的内容不太大,请手动包含它们。检查ParticipantValidator.h是否相关。如果没有,请删除理想情况下,你拿出一个完整的方案以'主()'函数复制正pastable在大致符合一个浏览器屏幕上一个* .cpp文件:) –

回答

0

没有功能assert()。这是一个宏而已。您可能包含了assert.h的错误版本,或者在之前包含的文件之一中是#define,它被评估为assert.h中的包含守护程序。

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

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

+0

没什么区别w.r.t.宏。 – jrok

+0

@ 200_success:为什么?提供一个理由。 –