Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

steventhai

macrumors newbie
Original poster
Sep 17, 2011
3
0
Hi everyone,

I am working on a command line tool program in Mac. In main, I have the following codes:

Code:
Fraction *p = [[Fraction alloc] initNumerator: 1 andDenominator: 4];

Mixed *a = [[Mixed alloc] initWhole:-1 andFractional: p];

The code for initWhole:andFractional: in the Mixed class is:

Code:
- (id) initWhole: (int) w andFraction: (Fraction *) f
{
    if (self == [super init])
    {
        whole = w;
        fractional = [[Fraction alloc] initNumerator: f.numerator andDenominator: f.denominator];
    }
    
    return self;
}

And the interface of Mixed class:
Code:
@interface Mixed : NSObject 
{
    //data
    int whole;
    Fraction *fractional;
}

The exception happened at the Mixed code in main above!!!

PS: The Fraction class is in good shape.

Please help me fix this issue. Thanks.
 
Last edited:
If that's your actual code, then this:
Code:
Mixed *a = [[Mixed alloc] initWhole:-1 [COLOR="Red"]andFractional[/COLOR]: p];
is not spelled the same as this:
Code:
- (id) initWhole: (int) w [COLOR="red"]andFraction[/COLOR]: (Fraction *) f

Accuracy is important in programming. So is completeness. Therefore, if the above doesn't pinpoint the problem, copy and paste your actual code, in its entirety.

Also post the complete actual text of the error message.
 
Hi,

Thanks a lot, it was my false. I mistyped the "andFraction", so I could not understand why the code did not work because there was nothing wrong with it.

Thanks again.
 
If you mistype or misspell certain things in your code, you should get a warning when you compile it. I recommend not ignoring warnings.
 
If you mistype or misspell certain things in your code, you should get a warning when you compile it. I recommend not ignoring warnings.

Going to go all "me too", in C-based languages(C, C++, Objective-C etc) warnings are usually a much bigger deal than they are in higher level languages. For instance, many, though certainly not all, Java warnings can usually be safely ignored(even if you shouldn't do so). However compiler warnings in (Objective)C(++) usually mean that there is a good chance your code will fail at run-time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.