Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 26, 2008, 11:01 AM   #1
zippyfly
macrumors regular
 
Join Date: Mar 2008
Why no * under polymorphism for superclass?

Hello. Need some help from the ObjC pros.

id generalData;
SpecificA *spec1 = [SpecificA new];
SpecificB *spec2 = [SpecificB new];

generalData = spec1;
...
generalData = spec2;
...

QUESTION: Why is it not

id *generalData;

missing the dereferencing operator *???

Aren't all objects in ObjC really just pointers to struts? And therefore, the id "superclass" type should have generalData declared as a pointer, no?

Thanks,
Quite Confused.
zippyfly is offline   0 Reply With Quote
Old Mar 26, 2008, 11:28 AM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by zippyfly View Post
QUESTION: Why is it not

id *generalData;

missing the dereferencing operator *???

Aren't all objects in ObjC really just pointers to struts? And therefore, the id "superclass" type should have generalData declared as a pointer, no?

Thanks,
Quite Confused.
id already is implicitly a pointer by definition, so you don't need to add the pointer specifier. I personally think they shouldn't have built it in (hidden it), and instead forced you to type id *myThing, as I think it would be more clear. But just read it as "id *" when you see it.
__________________
Go outside, the graphics are amazing!
HiRez is offline   0 Reply With Quote
Old Mar 26, 2008, 11:39 AM   #3
zippyfly
Thread Starter
macrumors regular
 
Join Date: Mar 2008
Thanks! Phew. You have no idea how much you helped clear up. It is really confusing for a beginner.

You are right, it should have been implemented to be declared specifically. After all, a lot of the syntax is supposed to force us to be clear about things and for the compiler to help check stuff at compile time.

I wonder if I can still use * without a compiler error? (Will try it later with gcc).

Actually, do you (or anyone else) have any general guideline about when to use * and when not to? (I still have not grokked a "golden rule" yet about this).

I know about using * to dereference, etc. a-la standard C; I am just sometimes confused why we use * and sometimes not, when dealing with objects.

I figured that anything inside the [brackets] is ObjC helping to "pre-process" the OOP stuff, so we don't use * inside the brackets, but outside of them, it sometimes gets confusing since there seem to exceptions to rules (as in the abovementioned original problem I had).

TIA!
zippyfly is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
why is apple the moral compass? Why doesn't flash work? Why no casino apps? akbrjg777 iPhone 16 Apr 22, 2010 05:46 PM
Why no Apple Remote Desktop for iphone? Semio1es iPhone 1 Jun 18, 2009 06:38 PM
Why no official rate plans for the 3G iphone??? Loonytik iPhone 4 Jun 16, 2008 03:29 PM
Why the MBP keeps scanning for AirMac under 10.5.2? hajime OS X 0 Feb 20, 2008 08:08 PM
Anyone else concerned why no online pre-orders yet for Leopard? powerbook911 OS X 24 Oct 15, 2007 08:55 AM


All times are GMT -5. The time now is 11:53 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC