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 protected])
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]