Re: delete map elements
David wrote:
On Mar 17, 11:32 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
David wrote:
I try to use map container and delete the elements. but there are
something wrong, please help me check it.
I'm sorry, what is wrong? Your code was not compilable. I tweaked it
to get it to work with empty default types and constructors. But for
all I know, it is not what you want. Here is what I did:
#include <map>
#include <string>
using namespace std;
class myclass {
};
class test{
protected:
map<string,myclass*> tests;
public:
test() {}
void AddMyclass(const string& myname,const myclass &st);
~test();
};
test::~test()
{
map<string,myclass*>::iterator ii;
for(ii=tests.begin();ii!=tests.end();++ii)
{
delete(ii->second);
}
tests.clear();
}
void test::AddMyclass(const string &myname,const myclass &st)
{
map<string,myclass*>::iterator ii;
myclass *newmyclass=NULL;
newmyclass=new myclass(st);
tests[myname]=newmyclass;
}
int main()
{
test my;
myclass st;
my.AddMyclass("new class",st);
}
Excuse the indentation, but I'm not going to bother fixing the minor
cosmetic problem.
So can you point out the problem? Or submit working code and point it
out there?
Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under the Creative Commons /
\ Attribution-Noncommercial-Share Alike 3.0 License /
\_____[http://creativecommons.org/licenses/by-nc-sa/3.0/]_____/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/