我试图在Xcode 8.2.1中编译此代码。这是一个非常简单的课程,但它没有编译。
代码:
#import <Foundation/Foundation.h>
@interface Fraction: NSObject
- (void) print;
- (void) setNumerator: (int) n;
- (void) setDenominator: (int) d;
@end
@implementation Fraction
{
int numerator;
int denominator;
}
- (void) print
{
NSLog (@"%i/%i", numerator, denominator); // <--- possible problem here?
}
- (void) setNumerator: (int) n
{
numerator = n;
}
- (void) setDenominator: (int) d
{
denominator = d;
}
@end
int main (int argc, char * argv[])
{
@autoreleasepool {
Fraction *myFraction;
myFraction = [Fraction alloc];
myFraction = [myFraction init];
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
NSLog (@"The value of myFraction is:");
[myFraction print]; // <---- possible problem here
}
return 0;
}
输出: 2017-02-08 17:13:00.789 prog3point2 [8643:13648415] myFraction的值是: (LLDB)
libdyld.dylib`start:
0x7fff9f7125ac <+0>: nop
0x7fff9f7125ad <+1>: movl %eax, %edi
0x7fff9f7125af <+3>: callq 0x7fff9f7125e0 ; symbol stub for: exit
0x7fff9f7125b4 <+8>: hlt
非常感谢,感谢此处的任何指导。