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: "Mondragon, Ian" <email@hidden>
- Date: Wed, 05 Mar 2003 13:08:57 -0600
britt,
1) in objc, [SomeClass alloc] simply allocates the memory needed for an
instance of SomeClass, whereas calling -init (or a subclassed implementation
of it) will provide you with a *usable* instance of SomeClass.
2) yup - you need to initialize the object (ala -init) in order to use it
3) @"string", does, in fact give you an autoreleased instance of an NSString
(this is the same as creating the same string with [NSString
stringWithCString:"string"], or [[[NSString alloc] initWithCString:"string"]
autorelease]).
4) an id is an un-typed pointer to an object instance (determined at
runtime). a Class is a pointer to a class data structure:
id foo = [[AnyClass alloc] init];
id bar
Class baz = [AnotherClass class];
bar = [[baz alloc] init];
hope that helps a bit...
- ian
>
-----Original Message-----
>
From: Britt Green [SMTP:email@hidden]
>
Sent: Wednesday, March 05, 2003 12:31 PM
>
To: email@hidden
>
Subject: Newbie coming to Cocoa from the world of C++
>
>
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();
>
>
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?
>
>
3) When using the @ sign in front of some quoted text, that
>
automatically converts that text into an NSString?
>
>
4) What's the difference between an id and a Class?
>
>
5) Obj C has two types of methods: class and instance. Are class
>
methods the same as C++'s static methods?
>
>
My apologies if these questions are answered in a FAQ somewhere. I
>
briefly looked for answers but didn't find any.
>
>
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.