小编Asm*_*zan的帖子

带有 GTest TYPED_TEST 的 C++ 多参数

我有闲置的测试集:

TEST_F(FactoryShould, createAFromAModule)
{
    const auto stateMachine = createStateMachine(EModule_A);
    const auto* typedStateMachine =
        dynamic_cast<const BackEnd<transitiontable::A, Guard>*>(stateMachine.get());
    ASSERT_TRUE(typedStateMachine);
}

TEST_F(FactoryShould, createBFromBModule)
{
    const auto stateMachine = createStateMachine(EModule_B);
    const auto* typedStateMachine =
        dynamic_cast<const BackEnd<transitiontable::B, Guard>*>(stateMachine.get());
    ASSERT_TRUE(typedStateMachine);
}
Run Code Online (Sandbox Code Playgroud)

有没有办法把它们变成类型化测试?我所看到的只是一个更改参数的解决方案,我有 2 个更改参数,EModule 可用于多个转换表,所以像 map 这样的东西看起来不错,但它可行吗?

c++ googletest

5
推荐指数
1
解决办法
2811
查看次数

超负荷的呼唤是暧昧的

我正在学习新的C++语义,我在这个程序中遇到错误:

#include <iostream>
#include <string>
#include <utility>

std::string foo(std::string str)
{
    return str + " call from normal";
}

std::string foo(const std::string& str)
{
    return str + " call from normal";
}

std::string foo(std::string&& str)
{
     return str + " call from ref ref";
}

int main()
{
    std::string str = "Hello World!";
    std::string res = foo(str);
    std::string&& res_ref = foo(std::move(str));
    std::cout << "Res ref = " << res_ref << std::endl;
    std::cout << "Str = " << str << std::endl; …
Run Code Online (Sandbox Code Playgroud)

c++ overload-resolution c++14

3
推荐指数
1
解决办法
1050
查看次数

标签 统计

c++ ×2

c++14 ×1

googletest ×1

overload-resolution ×1