Catch2 框架错误:未知类型名称“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 类,但它一直抛出相同的错误。
下面是代码:
#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
I'm using catch2 framework for unit testing. Below is the command I use for compiling the test file.
bin/tests: ./tests/tests.cc ./src/dna_strand.cc ./includes/dna_strand.hpp $(CXX) $(CXXFLAGS) ./tests/tests.cc ./src/dna_strand.cc -o $@
I'm trying to initialize constructor. I'm trying to use the class' method but it does not work. I'm guessing there is something wrong with my includes.
I also tried to initialize my DNAstrand class but it keeps throwing the same error.
Below is the code:
#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);
Belows are the 4 errors I get
unknown type name 'sample'
cannot use dot operator on a type
unknown type name 'DNA'
cannot use arrow operator on a type
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C++ 不允许在函数之外使用代码(不包括定义和声明),这意味着您需要将代码移至 TEST_CASE 宏内部。
C++ does not allow code outside of functions (excluding definitions and declarations), meaning you need to move your code inside the TEST_CASE macro.