gpt4 book ai didi

c++ - 使用具有 program_options::variables_map 作为参数的函数初始化 EXPECT_CALL 时出现编译器错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:05 25 4
gpt4 key购买 nike

我在尝试执行此操作时遇到了 EXPECT_CALL 方法的问题:

boost::program_options::variables_map vm;  
MyMock mock;
EXPECT_CALL(mock, MyMethod(vm)).WillOnce(Return(L""));

我的方法看起来像这样:

std::wstring MyMethod(const boost::program_options::variables_map &vm)

编译时出现错误:

Error   17  error C2676: binary '==' : 'const boost::program_options::variable_value' does not define this operator or a conversion to a type acceptable to the predefined operator C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\utility   

Error 10 error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const boost::program_options::variable_value' C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\utility

还有一些类似的错误。

最佳答案

此外,您可以创建自己的谓词作为匹配器,正如我发现在尝试与 boost 匹配时需要做的那样。

参见 here .

在你的测试中:

using :testing::Return;
using ::testing::Truly;
EXPECT_CALL( object , connectSlot( Truly( PredicateFunc ) ) ).Times( 1 ).WillOnce(Return( boost::signals::connection() ) );

当你有一个函数(或仿函数)

bool PredicateFunc( boost::signal0<void>::slot_type const& slot )
{
/* Custom matcher code */
return true | false;
}

关于c++ - 使用具有 program_options::variables_map 作为参数的函数初始化 EXPECT_CALL 时出现编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9001494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com