Re: Initializing C array of objects
Re: Initializing C array of objects
- Subject: Re: Initializing C array of objects
- From: Jean-Daniel Dupas <email@hidden>
- Date: Thu, 20 Dec 2007 12:18:31 +0100
Le 20 déc. 07 à 11:58, Ken Tozier a écrit :
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;
for (i = 0; i < 10; i++)
{
fooObject = (fooArray + i);
// in debugger, this shows that a new object is allocated rather
than putting it into the exsting aray
fooObject = [[Foo alloc] init];
}
How does one do something like this?
Thanks for any help;
Ken
Object in Obj-c cannot be referenced directly. You have to store
object pointer.
[[Foo alloc] init] return type is 'id' (a pointer to an object)
Foo **fooArray = malloc(10 * sizeof(Foo *));
int i;
for (i = 0; i < 10; i++)
{
fooObject[i] = [[Foo alloc] init];
}
_______________________________________________
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:
This email sent to email@hidden