Re: pointers in objective-c?
Re: pointers in objective-c?
- Subject: Re: pointers in objective-c?
- From: Glenn English <email@hidden>
- Date: Fri, 01 Aug 2008 13:10:22 -0600
- Organization: Sugarloaf Software
Wayne Shao wrote:
It seems that every object is a pointer in the sample code I have
seen. Is there any distinction between an object and its pointer?
In C++, C* c; would be an uninitialized pointer. But the following
line will creates an object with the constructor C().
C c;
It seems that there is no such equivalent syntax in Objective-C.
objects are created either from factory pattern or [[A alloc]
someInitMethod ....];
so, is it possible to write?
NSString a;
NSNumber b;
Sure. And it'll even compile. But you'd better not try to do much with
them:-)
<my understanding>
Objects in o-c are just plain old structs. And to get to them, you have
to have a pointer.
And the C++ syntax you refer to doesn't exist in o-c. At least it
doesn't do what it does in C++.
So C* c is indeed an uninitialized pointer to a C, just like it says it
is. And C c declares a struct of type C that you can't do anything with,
also just like it says.
C* c = [C new] (or equivalent) is the way do some useful work...
</my understanding>
--
Glenn English
email@hidden
_______________________________________________
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