Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Objective-C and Swift
  4. Objective C first program from the book, warning messages

Objective C first program from the book, warning messages

Scheduled Pinned Locked Moved Objective-C and Swift
swiftcomperformanceannouncement
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alla__
    wrote on last edited by
    #1

    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!

    B 1 Reply Last reply
    0
    • A Alla__

      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!

      B Offline
      B Offline
      BharathReddy V
      wrote on last edited by
      #2

      '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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups