gpt4 book ai didi

boost - Google mock 不能使用 std::vector 的 boost::variant 编译

转载 作者:行者123 更新时间:2023-12-01 01:18:08 25 4
gpt4 key购买 nike

我正在尝试为一些使用 boost::variant 的接口(interface)类创建 Google Mock 对象

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <boost/variant.hpp>
#include <vector>

typedef std::vector<int> VectorOfInt;
typedef boost::variant<VectorOfInt> VariantOfVector;

class InterfaceClass
{
public:
virtual ~InterfaceClass() {}
virtual void SetSome( const VariantOfVector& ) = 0;
virtual const VariantOfVector& GetSome() const = 0;
};

class MockInterfaceClass
{
public:
MOCK_METHOD1( SetSome, void( const VariantOfVector& ) );
MOCK_CONST_METHOD0( GetSome, const VariantOfVector&() );
};

当我编译它时

g++ mytest.cpp -o mytest



我明白了

/usr/include/boost/variant/detail/variant_io.hpp:64: error: no match for ‘operator<<’ in ‘((const boost::detail::variant::printer > >*)this)->boost::detail::variant::printer > >::out_ << operand’



boost::variant 是否与 std::vector 一起使用?似乎 boost::variant 适用于我定义的任何类型,但 std:vector 除外。为什么?

boost 版 - 1.45
g++ 版本 - 4.4.5

最佳答案

似乎模拟尝试将运算符 << 应用于您的变体。您必须为其内容定义 operator <<,即 std::vector 模板。

关于boost - Google mock 不能使用 std::vector 的 boost::variant 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10830248/

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