On Jun 11, 2008, at 3:01 AM, John Engelhart wrote:
-(MyObject *)copyAndCombineWith:(MyObject *)object
{
 MyObject *copy = malloc(sizeof(MyObject));
 memcpy(copy, object, sizeof(MyObject));
 copy->answer += answer;
 copy->integerRING += integerRing;
 return(copy);
}

Do not use malloc() to instantiate objects. Do not use memcpy() to copy objects.

Despite looking like a C pointer, (MyObject *) is not a pointer to a struct; it is a reference to an object. Do not treat objects like structs.

The fact that sending a subclass of the declared base class behaves in a nearly indistinguishable manner is the result of careful manipulation and subtle bending of the rules, not because it's literally so.

No, it's a deliberate use of the rules. Or rather, you are making up rules that don't exist, and that you certainly didn't read in the docs.

Based on your misconceptions, I suspect you may also not understand method overriding, which is a crucial concept.

I suggest you review the docs on Objective-C, in particular:

<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_9_section_1.html#//apple_ref/doc/uid/TP30001163-CH16-SW1 >
This chapter explains how static typing works and discusses some other features of Objective-C

Info on method overriding, in case you need it (I may be wrong about that), is here:

<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_2_section_4.html#//apple_ref/doc/uid/TP30001163-CH11-BAJCDADF >

--Andy




--Andy

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to