Re: Newbie coming to Cocoa from the world of C++
Re: Newbie coming to Cocoa from the world of C++
- Subject: Re: Newbie coming to Cocoa from the world of C++
- From: publiclook <email@hidden>
- Date: Wed, 5 Mar 2003 20:29:54 -0500
On Wednesday, March 5, 2003, at 01:30 PM, Britt Green wrote:
Hello all,
I've recently picked up Learning Cocoa with Objective C in order to
write apps for the Macintosh. I'm coming from a C++ background and have
some basic questions about Obj C that I'm hoping people can answer.
Basically I'm trying to find analogues between the two languages.
1) In Obj C, instantiating an object is done like this:
NSObject * myObject = [NSObject alloc];
Is this equal to doing the following C++ command:
MyObject* foo = new MyObject();
Following the Cocoa conventions:
NSObject *myObject = [[NSObject alloc] init];
2) In C++ one doesn't explicitly call the constructor when an object is
created. However, in Obj C one needs to call the init method, correct?
Following the Cocoa conventions, yes.
3) When using the @ sign in front of some quoted text, that
automatically converts that text into an NSString?
It directs the compiler to reserve storage for the string at compile
time so that no allocation is needed at runtime.
4) What's the difference between an id and a Class?
An id is a pointer to any instance of any class.
Class is a pointer any instance of class "class".
All classes are instances of the conceptual class "class".
Because classes are instances, id can point to a class as well as to
any other instance.
5) Obj C has two types of methods: class and instance. Are class
methods the same as C++'s static methods?
No. Objective-C class methods a polymorphic. C++ static member
functions a just functions. C++ doesn't have methods at all. It has
member functions and some of the member functions are polymorphic by
virtue of being declared virtual.
My apologies if these questions are answered in a FAQ somewhere. I
briefly looked for answers but didn't find any.
The central concept of Objective-C is the message. An object is
anything that can receive messages. Objective-C classes can receive
messages so classes ARE objects.
In C++, all concept of the class is removed by the compiler. Even with
RTTI, only an identifier for the class is preserved. Objective-C
preserves all of the "meta" information about classes and classes are
first class objects like anything else.
Thanks for the assistance!
Britt
=====
"The ocean, she is strange and wonderous, filled with animals that
disturb even a Frenchman."
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.