【发布时间】:2012-03-21 02:00:43
【问题描述】:
您好,谁能告诉我为什么 VS2010 给我这个代码的错误,我看不出它有什么问题?
错误代码:错误 C2679:二进制“=”:未找到采用“std::vector<_ty>”类型右侧操作数的运算符(或没有可接受的转换)
// Elements container
typedef std::vector<CFVFElementPtr> ElementArray;
typedef std::map<CVertexSemantic::Type, ElementArray> ElementsMap;
// Create an empty array of elements
ElementsMap::value_type::second_type allElements;
// Concatinate each std::vector found within the map
std::transform(m_elementsMap.begin(), m_elementsMap.end(),
std::insert_iterator<ElementArray>(allElements, allElements.end()),
select2nd<ElementsMap::value_type>() );
我想做的就是这个
for (auto i = m_elementsMap.begin(); i != m_elementsMap.end(); ++i)
{
const ElementArray& elements = (*i).second;
allElements.insert(allElements.end(), elements.begin(), elements.end());
}
作为对 Pablo 的回应,我尝试创建一个接受 ElementArray 数组的自定义迭代器,但我现在遇到了一大堆错误。
template < class Container >
class container_insert_interator
{
public:
typedef container_insert_interator<Container> this_type;
typedef Container container_type;
typedef typename Container::const_reference const_reference;
typedef typename Container::value_type valty;
explicit container_insert_interator (Container& cont, typename Container::iterator iter)
: container(&cont), iter(iter)
{ }
this_type& operator = (typename const_reference value)
{
iter = container->insert( iter, std::begin(value), std::end(value) );
++iter;
return *this;
}
this_type& operator* ()
{
return *this;
}
this_type& operator++ ()
{
return *this;
}
this_type operator++ (int)
{
return *this;
}
protected:
Container* container; // pointer to container
typename Container::iterator iter ; // iterator into container
};
【问题讨论】:
-
如果有人想知道select2nd 是什么,它只会返回 std::map 的 value_type 的 std::pair
.second。