D
David
Hi all,
I try to use map container and delete the elements. but there are
something wrong, please help me check it.
class test{
protected:
map<string,myclass*> tests;
public:
test();
void AddMyclass(const string& myname,const myclass &st);
~test();
};
suppose myclass has been defined before.
and
test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
{
delete(ii->second);
}
tests.clear();
}
int main()
{
test my;
myclass st;
my.AddMyclass("new class",st);
}
But when the code exits from the main function, there was an error
message saying that "Object reference not set to an instance of an
object.".
I think it is caused by the test's destructor function. But I don't
know where is the problem. Please help me. Thanks
I try to use map container and delete the elements. but there are
something wrong, please help me check it.
class test{
protected:
map<string,myclass*> tests;
public:
test();
void AddMyclass(const string& myname,const myclass &st);
~test();
};
suppose myclass has been defined before.
and
test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
{
delete(ii->second);
}
tests.clear();
}
int main()
{
test my;
myclass st;
my.AddMyclass("new class",st);
}
But when the code exits from the main function, there was an error
message saying that "Object reference not set to an instance of an
object.".
I think it is caused by the test's destructor function. But I don't
know where is the problem. Please help me. Thanks