I have defined a class that contains a std::list
as a member. When I create an object of that class, I expected the std::list to be empty. However, I queried the iterators returned by begin()
and end()
and found that they were not equal.
How can I ensure that my std::list member is empty on initial construction of the object?
Here is the code for my class:
typedef int ShapeHandle;
typedef void o_gadget;
class Gadget
{
public:
Gadget( int c_id, int g_id, void * desc, size_t numbytes ):
class_id(c_id), gadget_id(g_id)
{
memory = malloc( numbytes );
father = 0;
rightbro = 0;
leftbro = 0;
firstchild = 0;
lastchild = 0;
active = false;
update = false;
}
void * memory;
std::list<ShapeHandle> myshapes;
std::list<o_gadget *> children;
int class_id;
int gadget_id;
o_gadget * father;
o_gadget * rightbro;
o_gadget * leftbro;
o_gadget * firstchild;
o_gadget * lastchild;
bool active;
bool update;
};
I compared the iterators like this:
...
// search the tree stopping when we find the ID
Gadget * info = gadgets[from];
std::list<o_gadget *>::iterator iter = info->children.begin();
while( target == 0 && iter != info->children.end() )
{
FindGadget(ID, *iter, target);
iter++;
}
...
I didn't expect that on inspecting a new Gadget
, that while
loop would be entered. I know that target == 0
is true, so I figured that iter != info->children.end()
was also true. However, I am not inspecting these values in a debugger.
EDIT
I'm so sorry everyone. This is clearly wrong. I've done it again. I've posted a bug that isn't actually there. I can't reproduce it now. Can you all vote to close it - or can I close this thing myself?