Debugging Question

Discussion in 'Mac Programming' started by MountainDev, Oct 2, 2009.

  1. MountainDev macrumors newbie

    Joined:
    Oct 2, 2009
    #1
    Anyone know why I am getting warnings on the following? The error seems to be coming from Fraction.M. I get two warning:

    1. incomplete implemenation of class 'Fraction'
    2. method definition for '-initwithNumerator:denominator:' not found.

    Please help!


    FRACTION.H

    Code:
    #import <Foundation/NSObject.h>
    
    @interface Fraction: NSObject {
        int numerator;
        int denominator;
    }
    
    -(void) print;
    -(Fraction*) initwithNumerator: (int) n denominator: (int) d;
    -(void) setNumerator: (int) n andDenominator: (int) d;
    -(int) numerator;
    -(int) denominator;
    @end
    FRACTION.M

    Code:
    #import "Fraction.h"
    #import <stdio.h>
    
    @implementation Fraction
    -(void) print {
        printf( "%i/%i", numerator, denominator );
    }
    
    -(Fraction*) initWithNumerator: (int) n denominator: (int) d {
        self = [super init];
    	
    	if ( self ) {
    		[self setNumerator: n andDenominator: d];
    	}
    	
    	return self;
    }
    
    -(void) setNumerator: (int) n andDenominator: (int) d {
    	numerator = n;
    	denominator = d;
    }
    
    //-(void) setNumerator: (int) n {
    //	numerator = n;
    //}
    
    //-(void) setDenominator: (int) d {
    //    denominator = d;
    //}
    
    
    -(int) numerator {
        return numerator;
    }
    
    -(int) denominator {
        return denominator;
    }
    @end
    MAIN.M

    Code:
    #import <stdio.h>
    #import "Fraction.h"
    
    int main( int argc, const char *argv[] ) {
        // create a new instance
        Fraction *frac = [[Fraction alloc] initwithNumerator: 3 denominator: 7];
    	
        // print it
        printf( "The fraction is: " );
        [frac print];
        printf( "\n" );
    	
        // free memory
        [frac release];
    	
        return 0;
    }
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    You have a capital W in the declaration of initWith... but call it with a lowercase w.
     
  3. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #3
    Took me a while to spot, but method names are case sensitive.

    Meaning initwithNumerator... is not the same as initWithNumerator...

    You declared the later, but used the former in the main();


    Thats one reason to love the Xcode's auto filling method name feature. Just start typing init and as long as xcode fills in the right one hit tab. I almost NEVER type in the full name for methods, in face almost never more than the first letter or two.

    EDIT: Darn you Catfish_Man!!!
     
  4. MountainDev thread starter macrumors newbie

    Joined:
    Oct 2, 2009

Share This Page