![](/img/trans.png)
[英]clang-tidy bundled with Qt Creator [clang-diagnostic-error]
[英]Catch2 Framework Error: unknown type name 'DNA'clang-tidy(clang-diagnostic-error)
我正在使用 catch2 框架進行單元測試。 下面是我用來編譯測試文件的命令。
bin/tests: ./tests/tests.cc./src/dna_strand.cc./includes/dna_strand.hpp $(CXX) $(CXXFLAGS)./tests/tests.cc./src/dna_strand.cc -o $@
我正在嘗試初始化構造函數。 我正在嘗試使用類的方法,但它不起作用。 我猜我的包含有問題。 我還嘗試初始化我的 DNAstrand class 但它一直拋出相同的錯誤。
下面是代碼:
#ifndef CATCH_CONFIG_MAIN
# define CATCH_CONFIG_MAIN
#endif
#include <catch/catch.hpp>
#include <iostream>
#include "dna_strand.hpp"
#include "node.hpp"
DNAstrand sample();
sample.PushNode('h'); // <- error
DNAstrand\* DNA = new DNAstrand();
DNA->SpliceIn('h'); // <- error
TEST_CASE("Does nothing", "\[does-nothing\]") { REQUIRE(true == true);
下面是我得到的 4 個錯誤
unknown type name 'sample'
cannot use dot operator on a type
unknown type name 'DNA'
cannot use arrow operator on a type
C++ 不允許函數之外的代碼(不包括定義和聲明),這意味着您需要將代碼移動到 TEST_CASE 宏中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.