• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Initializing C array of objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Initializing C array of objects


  • Subject: Initializing C array of objects
  • From: Ken Tozier <email@hidden>
  • Date: Thu, 20 Dec 2007 05:58:49 -0500

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];
}

Also tried allocating as array of Foo pointers like so

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

int		i;

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Initializing C array of objects
      • From: Andrew Farmer <email@hidden>
    • Re: Initializing C array of objects
      • From: email@hidden
    • Re: Initializing C array of objects
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Re: Trouble with Leopard's newly enhanced NSSplitView
  • Next by Date: Re: Initializing C array of objects
  • Previous by thread: Re: Adding category @interface to header file causes IB to freak out?
  • Next by thread: Re: Initializing C array of objects
  • Index(es):
    • Date
    • Thread