i'm having a strange warning here. the following code works fine:
operators = [[NSMutableArray alloc] init];
Add * test = [Add alloc];
[operators addObject:[test initOperatorType:OPERATOR_TYPE
priority:ADDITIVE_OPERATOR_PRIORITY symbol:@"+"]];
on the other hand if i merge the last two lines like this:
[operators addObject:[[Add alloc] initOperatorType:OPERATOR_TYPE
priority:ADDITIVE_OPERATOR_PRIORITY symbol:@"+"]];
i get a warning: passing argument 1 of 'addObject:' from incompatible
pointer type
anyone a guess?
> hi!
Hi. A little advice up front: This isn't strictly an appropriate
newsgroup. You're asking for help with a specific class library on a
group dedicated to a language. In the future, I'd recommend posting such
questions to comp.sys.mac.programmer.* groups. They're more appropriate
*and* offer the benefit of more eyeballs looking at your question.
The way that "works" is a coding error. The variable 'test' points to a
chunk of memory that has been allocated and had only the most basic
initialization performed - enough to tell it that it's an 'Add' instance
and that's about it. Since there can be some odd side effects of
separating allocation and initialization, I wouldn't really trust the
fact that it works. I'd be more inclined to say the error you get when
doing it the right way is indicative of something hinky that should be
fixed.
Having said that, it's hard to tell what's really going wrong without
more information. I can't manufacture a situation the exhibits what
you're seeing. How is your initializer declared? (And, for that matter,
defined?) Do you get any warnings? What happens if you switch around the
first example so the alloc/init happen together and then pass the fully
constructed object to addObject:?
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Guesses:
1.) You made an error: you declared initOperatorType: as returning
something other than (id). All inits should return id. Probably
(Operator *)
2.) You made a second error. In your @interface declaration for whatever
class you declared initOperatorType as returning, you didn't derive from
NSObject:
@interface Operator : NSObject // <- forgotten?
...
@end
Just guesses. Am I close?
--
David Phillip Oster