Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / January 2006



Tip: Looking for answers? Try searching our database.

how to get pointer value off of an array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wizumwalt@gmail.com - 27 Jan 2006 02:53 GMT
Hi all,

I'm using objective-c++ and I'm having a problem pulling a pointer off
of an NSMutableArray. I show how I'm adding a pointer to the array
below, but after that, I don't think I'm pulling it off correctly.

Any help much appreciated.

--- adding pointer to array

    NSMutableArray *myPatterns;
    NQ::Pattern *pattern = new NQ::Pattern(a, b, c);

    // ...

    [myPatterns addObject:[NSValue valueWithPointer:pattern]];

--- get value off of array

    NSEnumerator *enumerator;
       enumerator = [myPatterns objectEnumerator];

      NQ::Pattern *pattern;

    while (pattern = (NQ::Pattern *) [[myPatterns enumerator]
pointerValue]) {
        NSLog(@"id = %d", pattern->get_id());
    }
Michael Ash - 27 Jan 2006 07:29 GMT
> Hi all,
>
[quoted text clipped - 3 lines]
>
> Any help much appreciated.

Please try to be more specific about your problem. Dumping a bunch of code
and saying "I'm having a problem" makes it difficult to help you. Provide
as much information about the problem as you can, such as whatever
happened that made you think you have a problem in the first place, any
error messages that occurred, what you thought should happen, what
actually did happen, etc.

> --- get value off of array
>
[quoted text clipped - 5 lines]
>        while (pattern = (NQ::Pattern *) [[myPatterns enumerator]
> pointerValue]) {

NSArray doesn't have an -enumerator message, so this line won't work.
Perhaps you meant to say [[enumerator nextObject] pointerValue]?

Also keep in mind that you must be very careful in this situation, because
NSArray cannot properly destroy your objects in situations where it
normally would, such as when the array itself is deallocated. Consider
writing a custom Objective-C wrapper class for it which handles proper
destruction of the inner C++ class, or use a CFMutableArray with custom
callbacks.

Signature

Michael Ash
Rogue Amoeba Software

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.