std::set::find won't work...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Mng
{
public:
	Mng();
	//...
	//m_Bs may be changed by memberfunctions of the class
        //m_update may only be changed by Mng::Update and initialized empty
	void Update(std::vector<B>& n, std::vector<B>& l);
private:
	std::vector<B> m_Bs;
	std::set<int> m_update;
};


//n should contain new added B's, l should contain lost B's
void Mng::Update(std::vector<B>& n, std::vector<B>& l)
{
	std::vector<B>::iterator it = m_Bs.begin();
	while(it!=m_Bs.end())
	{
		int id = it->Id();
		BOOL e = it->Exists();
		std::set<int>::iterator ut = m_update.find(id);
		if(e && ut==m_update.end())
		{
			m_update.insert(id);
			n.push_back(*it);
		}
		else if (!e && ut!=m_update.end())
		{
			m_update.erase(id);
			l.push_back(*it);
		}
		++it;
	}
}


But it seems that ut is always m_update.end(). What's wrong?
There isn't enough information there to diagnose your problem, however I can guarantee
you that std::set<T>::find() works as long as T meets the requirements for a sequence
container (int does).

Topic archived. No new replies allowed.