作者:baobeimengmen6857124 | 来源:互联网 | 2023-01-29 02:44
我有一些在Windows(Visual Studio 2017)上编写的单元测试,我需要在Linux(GCC 4.9.2-我受此版本困扰...)上移植它们。我为我的问题提供了一个简单的示例,该示例在Windows上可以很好地编译(我认为它不应该像MyParamType
e模板基类的依赖类型那样进行编译),而不能在Linux上进行编译。
例:
#include
template
struct MyTest : public testing::Test
{
using MyParamType = T;
};
using MyTypes = testing::Types;
TYPED_TEST_CASE(MyTest, MyTypes);
TYPED_TEST(MyTest, MyTestName)
{
MyParamType param;
}
在成员函数'virtual void MyTest_MyTestName_Test :: TestBody()'中:错误:在此范围MyParamType参数中未声明'MyParamType';
通过更改为:
TYPED_TEST(MyTest, MyTestName)
{
typename MyTest::MyParamType param;
}
代码可以编译,但是看起来很丑陋。
有没有一种简单/好的方法来从中获取模板参数类型TYPED_TEST
?
1> Richard Hodg..:
答案隐藏在文档中:
#include
template
struct MyTest : public testing::Test
{
using MyParamType = T;
};
using MyTypes = testing::Types;
TYPED_TEST_CASE(MyTest, MyTypes);
TYPED_TEST(MyTest, MyTestName)
{
// To refer to typedefs in the fixture, add the 'typename TestFixture::'
// prefix. The 'typename' is required to satisfy the compiler.
using MyParamType = typename TestFixture::MyParamType;
}
https://github.com/google/googletest/blob/master/googletest/docs/advanced.md