Click here to Skip to main content
16,008,490 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralCOM+ Application to Register my COM Component (VC++). Please Help ......... Pin
Atif Bashir28-Aug-03 21:08
Atif Bashir28-Aug-03 21:08 
GeneralRe: COM+ Application to Register my COM Component (VC++). Please Help ......... Pin
Brad Sokol29-Aug-03 2:52
Brad Sokol29-Aug-03 2:52 
GeneralXP Explorer Search like View Pin
Wild Wild Mike27-Aug-03 10:01
Wild Wild Mike27-Aug-03 10:01 
GeneralHandling ActiveX Events in VB Pin
nalinikanth26-Aug-03 3:34
nalinikanth26-Aug-03 3:34 
QuestionHow to run a script (.vbs) in VC++, Please help .... Pin
Atif Bashir26-Aug-03 2:43
Atif Bashir26-Aug-03 2:43 
AnswerRe: How to run a script (.vbs) in VC++, Please help .... Pin
palbano28-Aug-03 8:40
palbano28-Aug-03 8:40 
AnswerRe: How to run a script (.vbs) in VC++, Please help .... Pin
Vi229-Aug-03 4:36
Vi229-Aug-03 4:36 
Generalkeeping track of pointers to objects with STL Pin
Jeremy Pullicino26-Aug-03 0:04
Jeremy Pullicino26-Aug-03 0:04 
I have an stl list of pointers to objects.

When I need to insert an object to the list, I new it and push_back its
pointer.

When the list is not needed any more, I iterate through the entire list and
I delete each pointer.

First question: Is there a more elegant way to do this or is my
implementation ok?

Sometimes I wish to copy a pointer for one list into another list, meaning
that the two lists will contain a pointer to the same object.

When the first list is destroyed, I delete all pointers inside it, as
mentioned above.

When the second list is destroyed, I do the same, however my pointers are
already deleted and this of course crashes the program.

My first thought was to implement reference counting on my object, however I
am unsure of where to increment the reference.

The code looks something like this:

std::list<cmyobj*> list1;
std::list<cmyobj*> list2;

CMyObj* pOBJ = new CMyObj;

list1.push_back(pOBJ);

list2.insert(list2.begin(), list1.begin(), list1.end());

// delete all elements in list1

// delete all elements in list2 (crash)

When list2.insert is called, a copy of the pointer from list1 is inserted
into list2.

I will need to increment the reference of the pointer which is inserted,
however I am unsure of how to do this.

Does anyone have a solution to this?

Thanks in advance,



Jeremy Pullicino
C++ Developer

Homepage
GeneralRe: keeping track of pointers to objects with STL Pin
Joaquín M López Muñoz26-Aug-03 3:32
Joaquín M López Muñoz26-Aug-03 3:32 
GeneralRe: keeping track of pointers to objects with STL Pin
Nemanja Trifunovic26-Aug-03 5:07
Nemanja Trifunovic26-Aug-03 5:07 
QuestionHow to load a cursor dymamically, from a dynamically created bitmap? Pin
Garuna25-Aug-03 22:20
Garuna25-Aug-03 22:20 
GeneralWTL + Time/Date information Pin
Ernesto D.23-Aug-03 22:00
Ernesto D.23-Aug-03 22:00 
GeneralRe: WTL + Time/Date information Pin
Stuart Dootson23-Aug-03 23:18
professionalStuart Dootson23-Aug-03 23:18 
GeneralRe: WTL + Time/Date information Pin
Steve S25-Aug-03 22:19
Steve S25-Aug-03 22:19 
GeneralRe: WTL + Time/Date information Pin
Ernesto D.26-Aug-03 9:46
Ernesto D.26-Aug-03 9:46 
GeneralRe: WTL + Time/Date information Pin
Rob Caldecott26-Aug-03 23:23
Rob Caldecott26-Aug-03 23:23 
GeneralRe: WTL + Time/Date information Pin
Ernesto D.27-Aug-03 14:54
Ernesto D.27-Aug-03 14:54 
GeneralRe: WTL + Time/Date information Pin
Rob Caldecott27-Aug-03 22:05
Rob Caldecott27-Aug-03 22:05 
GeneralRe: WTL + Time/Date information Pin
Steve S27-Aug-03 22:36
Steve S27-Aug-03 22:36 
GeneralRe: WTL + Time/Date information Pin
Ernesto D.28-Aug-03 17:12
Ernesto D.28-Aug-03 17:12 
GeneralRe: WTL + Time/Date information Pin
Steve S28-Aug-03 22:01
Steve S28-Aug-03 22:01 
GeneralRe: WTL + Time/Date information Pin
TW7-Sep-03 23:35
TW7-Sep-03 23:35 
Generalwheather can introduce book about ATL developing, best offer its E- version and HTTP link address. Pin
simonchen.net21-Aug-03 23:27
simonchen.net21-Aug-03 23:27 
GeneralRe: wheather can introduce book about ATL developing, best offer its E- version and HTTP link address. Pin
Roger Stewart25-Aug-03 15:23
professionalRoger Stewart25-Aug-03 15:23 
GeneralRe: wheather can introduce book about ATL developing, best offer its E- version and HTTP link address. Pin
Steve S25-Aug-03 22:34
Steve S25-Aug-03 22:34 

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.