discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C beginner question


From: Michael Thaler
Subject: Objective-C beginner question
Date: Thu, 9 Mar 2006 15:10:28 +0100
User-agent: KMail/1.7.2

Hi,

I am new to Objective-C. I tried to compile one of the examples of Kochan's 
book "Programming in Objective-C":

#import <stdio.h>
#import <objc/Object.h>

@interface Fraction: Object
{
    int numerator;
    int denominator;
}

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;

@end

@implementation Fraction;

-(void) print
{
    printf(" %i/%i ", numerator, denominator);
}

-(void) setNumerator: (int) n
{
    numerator = n;
}

-(void) setDenominator: (int) d
{
    denominator = d;
}

@end;

int main(int argc, char *argv[])
{
    Fraction *myFraction;
    myFraction = [Fraction alloc];
    myFraction = [Fraction init];
    
    [myFraction setNumerator: 1];
    [myFraction setDenominator: 3];
    
    printf("The value of myFraction is: ");
    [myFraction print];
    printf("\n");
    [myFraction free];
}

It compiles fine (I compiled it with gcc-3.4 fraction_class.m -o 
fraction_class -l objc), but when I run the program, I get

./fraction_class
error: Fraction (class)
Fraction does not recognize setNumerator:
Aborted

The system is Debian Sarge with gcc 3.4 (also happens with gcc 3.3).

Can someone tell me what I am doing wrong here?

Greetings,
Michael




reply via email to

[Prev in Thread] Current Thread [Next in Thread]