我正在尝试为某些使用boost :: variant
的接口类创建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:错误:'运算符&lt;&lt;'在'((const boost :: detail :: variant :: printer&gt;&gt;&gt; *)this) - &gt; boost :: detail :: variant :: printer&gt; &gt; :: out_&lt;&lt;操作数”
boost :: variant是否适用于std :: vector?似乎boost :: variant适用于我定义的任何类型,但std:vector。为什么呢?
Boost版本 - 1.45 g ++版本 - 4.4.5
答案 0 :(得分:2)
似乎模拟尝试应用运算符&lt;&lt;你的变种。你必须定义operator&lt;&lt;其内容,即std :: vector template。
答案 1 :(得分:1)
正如Igor R.回答的那样,你需要添加运算符&lt;&lt; (没有名称空间)像这样:
std::ostream& operator <<(std::ostream& out, VariantOfVector const& rhs)
{
//Print or apply your visitor to **rhs**
return out;
}