我在编写一些测试的 C++ 文件中遇到此错误:
error: no member named 'Session' in namespace 'Catch'
testResult = Catch::Session().run(test_argc, test_argv);
~~~~~~~^
查看 catch.hpp 单个头文件,我注意到应该实现 Session() 成员函数的代码是灰色的,可能是因为我找不到某个地方的 #ifdef。
是否有任何宏可以设置为使用 session 类?
捕获版本:1.5.3 和 1.5.6。
引用:https://github.com/philsquared/Catch/blob/master/docs/own-main.md
最佳答案
您正试图从一个文件中调用 Catch::Session
的构造函数,而您没有定义要执行的自己的 main
。根据documentation on defining your own main ,应该只有一个 Catch::Session
实例:
Catch::Session session; // There must be exactly once instance
Catch 可能会阻止在翻译单元中构造 Catch::Session
,因为它不能在自定义 main
定义中使用(因为这是它应该的地方被使用),以防止您在编译时犯的错误。
关于c++ - Catch 测试框架问题:无法使用 Catch::Session(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38105783/