Objective C first program from the book, warning messages
-
Hello! I am new to this forum, and new to programming, although I have already reached chapter 18 of Programming in C textbook. Please, take a look at the program I typed in from the book, and warning messages I receive. I would be grateful for explanation on what I am doing wrong. I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3. 1) I created a file with the command: touch prog18-2.m// Program ot work with fractions - Objective-C version 2) Program #import #import //------ @interface section --------- @interface Fraction: Object { int numerator; int denominator; } -(void) set_numerator: (int) n; -(void) set_denominator: (int) d; -(void) print; @end // ----- @implementation section ------- @implementation Fraction; // getters -(int) numerator { return numerator; } -(int) denominator { return denominator; } //setters -(void) set_numerator: (int) num { numerator = num; } -(void) set_denominator: (int) denom { denominator = denom; } //other -(void) print { printf("The value of the fraction is %i/%i\n", numerator, denominator); } @end //-------- program section ----------- int main(void) { Fraction* my_fract; my_fract = [Fraction new]; [my_fract set_numerator: 1]; [my_fract set_denominator: 3]; printf("The numerator is %i, and teh denominator is %i\n", [my_fract numerator], [my_fract denominator]); [my_fract print]; [my_fract free]; //frees the memory that was used by Fraction object return 0; } 3) I compiled it with: gcc -framework Foundation prog18-2.m -o prog18-2 4) Terminal generated the following: prog18-2.m: In function ‘main’: prog18-2.m:58: warning: ‘Fraction’ may not respond to ‘+new’ prog18-2.m:58: warning: (Messages without a matching method signature prog18-2.m:58: warning: will be assumed to return ‘id’ and accept prog18-2.m:58: warning: ‘...’ as arguments.) prog18-2.m:71: warning: ‘Fraction’ may not respond to ‘-free’ Thank you!
-
Hello! I am new to this forum, and new to programming, although I have already reached chapter 18 of Programming in C textbook. Please, take a look at the program I typed in from the book, and warning messages I receive. I would be grateful for explanation on what I am doing wrong. I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3. 1) I created a file with the command: touch prog18-2.m// Program ot work with fractions - Objective-C version 2) Program #import #import //------ @interface section --------- @interface Fraction: Object { int numerator; int denominator; } -(void) set_numerator: (int) n; -(void) set_denominator: (int) d; -(void) print; @end // ----- @implementation section ------- @implementation Fraction; // getters -(int) numerator { return numerator; } -(int) denominator { return denominator; } //setters -(void) set_numerator: (int) num { numerator = num; } -(void) set_denominator: (int) denom { denominator = denom; } //other -(void) print { printf("The value of the fraction is %i/%i\n", numerator, denominator); } @end //-------- program section ----------- int main(void) { Fraction* my_fract; my_fract = [Fraction new]; [my_fract set_numerator: 1]; [my_fract set_denominator: 3]; printf("The numerator is %i, and teh denominator is %i\n", [my_fract numerator], [my_fract denominator]); [my_fract print]; [my_fract free]; //frees the memory that was used by Fraction object return 0; } 3) I compiled it with: gcc -framework Foundation prog18-2.m -o prog18-2 4) Terminal generated the following: prog18-2.m: In function ‘main’: prog18-2.m:58: warning: ‘Fraction’ may not respond to ‘+new’ prog18-2.m:58: warning: (Messages without a matching method signature prog18-2.m:58: warning: will be assumed to return ‘id’ and accept prog18-2.m:58: warning: ‘...’ as arguments.) prog18-2.m:71: warning: ‘Fraction’ may not respond to ‘-free’ Thank you!
'Fraction' class is subclass of 'Object'. But 'new' method is available in 'NSObject' class. That is the reason why it its showing warnings for you.