Reputation: 4025
I need help. When trying iterate over a set I get the following error:
Error 1 error C2440: 'initializing' : cannot convert from 'std::_Tree_const_iterator<_Mytree>' to 'compound_objectNS::Compound_object *' c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory 208
I got the following code: extract from file "compound_object.cpp":
typedef compound_objectNS::Compound_object OBJECT
bool OBJECT::operator== (const Compound_object &object) const
{
return this == &object;
}
bool OBJECT::operator< (const Compound_object &object) const
{
return this->m_numberOfObject < object.m_numberOfObject;
}
here to allow set to sort it elements I override operators "==" and " <"
client file:
for (objectImitatorNS::set<compound_objectNS::Compound_object*>::iterator it = Objects->begin();
it != Objects->end(); ++it)
{
this->m_imitatedObjects->insert(it);
}
As I figured out error is raised when line
this->m_imitatedObjects->insert(it)
executed.
How to solve this issue?
Upvotes: 1
Views: 251
Reputation: 38218
std::set::insert
(the version that takes one parameter) does not take an iterator. It takes a value. See here. You can try:
this->m_imitatedObjects->insert(*it);
Upvotes: 4
Reputation: 476980
Say this->m_imitatedObjects->insert(*it);
. You're inserting values.
Upvotes: 4