objective c - NSPointerArray access pointer fails -


i have code in cocoa library:

-(nspointerarray *)  getrequestsfromcalendar:(int) calid {     nspointerarray * reqs=[[nspointerarray alloc] initwithoptions:nspointerfunctionsopaquememory];      for(int i=0;i<5; ++i){         request * newreq=new request();         [reqs addpointer:newreq];     }      (nsuinteger i=0;i<5;++i) {         void * ptr=[reqs pointeratindex:i];         std::cout<<*((request *) ptr)<<std::endl;     } 

here have expected values printed "request1" "request1" "request1" "request1" "request1"

    return reqs; } 

when call function other cocoa library, , access nspointerarray,

nspointerarray * array=[obj getrequestsfromcalendar:1] (nsuinteger i=0; i<[array count]; ++i) {     void * ptr=[array pointeratindex:i];     std::cout<<*((request *) ptr)<<std::endl; } 

prints not expected values ????aod?)@"?? ....

request c++ class overloaded std::ostream & operator << , private members std::string name initialized "request1"

both libraries use automatic reference counting

the pointers seem free after calling function not sure. can help?


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -