Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initializing C array of objects






Hi

I'm writing a class that needs to allocate a C array of objects and am having some trouble getting the things initialized. Here's what I'm doing but it's giving me "lvalue" errors

Foo		*fooArray		= malloc(10 * sizeof(Foo)),
		*fooObject;

int		i;

for (i = 0; i < 10; i++)
{
	(fooArray + i) = [foo init];
}


I think you should use :

Foo **fooArray = malloc(10 * sizeof(Foo *));

for (int i = 0; 1 < 10; i++)
fooArray[i] = [[Foo alloc] init];


But, why not a NSArray?

:: marcelo.alves
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Initializing C array of objects (From: Ken Tozier <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.