gpt4 book ai didi

c++ - GMOCK 方法抛出编译错误

转载 作者:行者123 更新时间:2023-11-30 05:07:14 25 4
gpt4 key购买 nike

当我尝试像下面那样实现 GMOCK 方法时出现编译错误,但是当我删除它时代码和 MOCK 类工作正常:

MOCK_METHOD2(myfunc, void (std::shared_ptr<route>, std::unique_ptr<message, std::default_delete<message> >));

我得到以下编译错误:

error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = message; _Dp = std::default_delete<message>]'
MOCK_METHOD2(ship, void (std::shared_ptr<route>, std::unique_ptr<message, std::default_delete<message> >));
^
In file included from C:/tools/mingw64/x86_64-w64-mingw32/include/c++/memory:81:0,
......................................................................................
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/bits/unique_ptr.h:356:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
error: initializing argument 2 of 'R testing::internal::FunctionMocker<R(A1, A2)>::Invoke(A1, A2) [with R = void; A1 = std::shared_ptr<route>; A2 = std::unique_ptr<message>]'
R Invoke(A1 a1, A2 a2) {
^
In file included from ...

C:/tools/mingw64/x86_64-w64-mingw32/include/c++/tuple: In instantiation of 'constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long long unsigned int _Idx = 1ull; _Head = std::unique_ptr<message>]':
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/tuple:255:44: recursively required from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long long unsigned int _Idx = 1ull; _Head = std::unique_ptr<message>; _Tail = {}]'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/tuple:255:44: required from 'constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long long unsigned int _Idx = 0ull; _Head = std::shared_ptr<cmb::mim::MimChannel>; _Tail = {std::unique_ptr<message, std::default_delete<message> >}]'
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/tuple:531:30: required from 'constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with _T1 = std::shared_ptr<cmb::mim::MimChannel>; _T2 = std::unique_ptr<message>]'
C:/work/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:122:50: required from 'R testing::internal::FunctionMocker<R(A1, A2)>::Invoke(A1, A2) [with R = void; A1 = std::shared_ptr<cmb::mim::MimChannel>; A2 = std::unique_ptr<message>]'
C:/work/Mock.hpp:39:5: required from here
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/tuple:134:25: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = message; _Dp = std::default_delete<message>]'
: _M_head_impl(__h) { }

我不确定错误是什么以及如何修复它 - 评论或删除编译正常的 MOCK 方法声明?

最佳答案

我能够通过如下所述操作函数来解决问题:

MOCK_METHOD2(myfuncproxy, void (std::shared_ptr<route>, message&));

void myfunc((std::shared_ptr<route> r, std::unique_ptr<message, std::default_delete<message> > m)
{
myfuncproxy(r,*m.get());
}

关于c++ - GMOCK 方法抛出编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47565900/

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