• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: method caller mixup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: method caller mixup


  • Subject: Re: method caller mixup
  • From: Fritz Anderson <email@hidden>
  • Date: Sat, 17 Apr 2010 13:24:44 -0500

On 17 Apr 2010, at 1:02 PM, James Maxwell wrote:

> I have a couple of node-based classes, one to build a Lempel-Ziv tree (Incremental Parsing) and one to build a Trie. Both of these classes have an -initWithParent: method. Should be fine, I would think, but I'm getting a compiler error that a Trie node's initWithParent is expecting the Lempel-Ziv node as input. I can't see any reason why this would happen. Is there any tricky cause for a matching method name, in a totally different class, to get called? I tried cleaning the project, to no avail.
> It would be too complicated to post the code, but the context of the error is something like this:
>
> HSMM_TrieNode* newNode = [[HSMM_TrieNode alloc] initWithParent:aNode];
>
> And yes, "aNode" is very definitely an HSMM_TrieNode, not a Lempel-Ziv node. The HSMM_TrieNode class has no idea that the Lempel-Ziv node class even exists...
>
> Has anyone seen this kind of mixup?

It's not particularly tricky. +alloc returns an id, and Objective-C doesn't have operand-overloaded methods. There is nothing in your alloc/init expression that tells the _compiler_ which of the differently-defined initWithParent: methods you intend to use, so it picks one in some undefined way. In this case, it picked the one you didn't intend.

You can force the choice by casting the result of +alloc to the intended type:

[ (HSMM_TrieNode *)[HSMM_TrieNode alloc] initWithParent: aNode ]


	— F

_______________________________________________

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

  • Follow-Ups:
    • Re: method caller mixup
      • From: "Paul Sanders" <email@hidden>
References: 
 >method caller mixup (From: James Maxwell <email@hidden>)

  • Prev by Date: Re: Looking for examples of UIScrollView using Core Data
  • Next by Date: Supporting different orientations with UITabBarView?
  • Previous by thread: method caller mixup
  • Next by thread: Re: method caller mixup
  • Index(es):
    • Date
    • Thread