2014-04-06 63 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:爲什麼?提供一個理由。 –