Click here to Skip to main content
16,004,854 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionProblem using struct as std::map value type Pin
Manfr3d6-Jan-09 1:57
Manfr3d6-Jan-09 1:57 
AnswerRe: Problem using struct as std::map value type Pin
Franck Paquier6-Jan-09 2:49
Franck Paquier6-Jan-09 2:49 
AnswerRe: Problem using struct as std::map value type Pin
Stuart Dootson6-Jan-09 2:57
professionalStuart Dootson6-Jan-09 2:57 
AnswerRe: Problem using struct as std::map value type Pin
Malli_S6-Jan-09 3:00
Malli_S6-Jan-09 3:00 
AnswerRe: Problem using struct as std::map value type Pin
Sarath C6-Jan-09 3:07
Sarath C6-Jan-09 3:07 
GeneralRe: Problem using struct as std::map value type Pin
Manfr3d6-Jan-09 6:37
Manfr3d6-Jan-09 6:37 
GeneralRe: Problem using struct as std::map value type Pin
Sarath C6-Jan-09 6:47
Sarath C6-Jan-09 6:47 
AnswerRe: Problem using struct as std::map value type Pin
John R. Shaw7-Jan-09 7:57
John R. Shaw7-Jan-09 7:57 
map RectMap; <- error

typedef unsigned key_type; <- any type you want
std::map<key_type, SRect> RectMap; <- OK
SRect sr = {iX, iY, iW, iH}; <- should work
RectMap[iID] = sr;

OR

RectMap[iID] = {iX, iY, iW, iH}; <- should work

Only write something like RectMap[iID]->iX if you are storing pointers to type sRect in the map; which would be bad and stuped unless you have a really good reason for doing so.

If you are storing pointers ( std::map<key_type, SRect*> ) in the map, then you will need to write a method to free the memory pointed to by all those elements before you allow the map to be destroyed. If you are storing the actual data instead ( std::map<key_type, SRect> ), then the clean up will be automatic when the map is destroyed.

To recap:

... BAD ...

std::map<key_type, SRect*> RectMap; <- bad
RectMap[key] = new SRect(iX, iY, iW, iH); <- this is why it is bad
void cleanup_before_destruction() <- and this is why it is bad
{
    std::map<key_type, SRect*>::iterator i;
    for( i = RectMap.begin(); i != RectMap.end(); ++i )
        delete *i;
}


... GOOD ...

std::map<key_type, SRect> RectMap; <- good
SRect sr(iX, iY, iW, iH);
RectMap[key] = sr;


INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

Questionabout wstring Pin
vikramlinux6-Jan-09 1:28
vikramlinux6-Jan-09 1:28 
AnswerRe: about wstring Pin
Sarath C6-Jan-09 1:44
Sarath C6-Jan-09 1:44 
GeneralRe: about wstring Pin
vikramlinux6-Jan-09 1:47
vikramlinux6-Jan-09 1:47 
AnswerRe: about wstring Pin
ThatsAlok6-Jan-09 23:51
ThatsAlok6-Jan-09 23:51 
QuestionHow to launch interactive process from Service Pin
SNI6-Jan-09 0:36
SNI6-Jan-09 0:36 
AnswerRe: How to launch interactive process from Service Pin
«_Superman_»6-Jan-09 0:50
professional«_Superman_»6-Jan-09 0:50 
AnswerRe: How to launch interactive process from Service Pin
Stuart Dootson6-Jan-09 1:01
professionalStuart Dootson6-Jan-09 1:01 
GeneralRe: How to launch interactive process from Service Pin
SNI6-Jan-09 1:16
SNI6-Jan-09 1:16 
GeneralRe: How to launch interactive process from Service Pin
Iain Clarke, Warrior Programmer6-Jan-09 1:57
Iain Clarke, Warrior Programmer6-Jan-09 1:57 
GeneralRe: How to launch interactive process from Service Pin
Stuart Dootson6-Jan-09 2:53
professionalStuart Dootson6-Jan-09 2:53 
GeneralRe: How to launch interactive process from Service Pin
Iain Clarke, Warrior Programmer6-Jan-09 3:10
Iain Clarke, Warrior Programmer6-Jan-09 3:10 
GeneralRe: How to launch interactive process from Service Pin
Stuart Dootson6-Jan-09 4:21
professionalStuart Dootson6-Jan-09 4:21 
GeneralRe: How to launch interactive process from Service Pin
Iain Clarke, Warrior Programmer6-Jan-09 4:50
Iain Clarke, Warrior Programmer6-Jan-09 4:50 
GeneralRe: How to launch interactive process from Service Pin
CPallini6-Jan-09 4:23
mveCPallini6-Jan-09 4:23 
GeneralRe: How to launch interactive process from Service Pin
Iain Clarke, Warrior Programmer6-Jan-09 4:47
Iain Clarke, Warrior Programmer6-Jan-09 4:47 
GeneralRe: How to launch interactive process from Service Pin
CPallini6-Jan-09 5:06
mveCPallini6-Jan-09 5:06 
GeneralRe: How to launch interactive process from Service Pin
Iain Clarke, Warrior Programmer6-Jan-09 5:24
Iain Clarke, Warrior Programmer6-Jan-09 5:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.