|
From: Ioannis V. <iv...@em...> - 2003-07-10 00:10:59
|
=20
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Shane =
Bryldt
Sent: Thursday, July 10, 2003 2:00 AM
To: Ioannis Vranos
Cc: C++
Subject: Re: [Dev-C++] STL Map question
Yes, I appologize for not including the header definition. Here it is.
=20
#ifndef USERLIST_H
#define USERLIST_H
=20
#include <map.h>=20
=20
#include <cmap>
=20
=20
class User;
=20
class UserList {
public:
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}=20
=20
Why don't you use std::string?
=20
=20
};
typedef std::map<const char *, User *, ltstr> UserMap;
=20
UserList();
~UserList();
=20
void AddUser(User *pUser);
bool DeleteUser(const char *pNick);
User *FindUser(const char *pNick);
unsigned long Length();
=20
UserMap m_mapUsers;
};
=20
=20
#endif=20
=20
=20
This is really dangerous stuff! At first keep in mind that in the code:
=20
=20
UserList whatever;
=20
// ...
=20
whatever.FindUser("Johnson");
=20
whatever.FindUser("Johnson");
=20
=20
These two "Johnson" have different addresses! So better use std::string.
=20
=20
The specific portion of code you had provided and suspected that it =
crashes,
seems clean. The crash must occur somewhere else (soemwhere in those =
char
*s).
=20
Use std::string now! :-)
=20
=20
=20
=20
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
<http://www.noicys.freeurl.com/>=20
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net =
<http://www.noicys.cjb.net/>
=20
|