我得到這個問題,我在我的主要文件都評論:預計標識符或 '(' 失蹤
#import <Foundation/Foundation.h>
#import "Person.h"
int main (int argc, const char * argv[])
{
// Create an instance of Person
Person *person = [[Person alloc]init];
// Give the instance variables interesting values
[person setWeightInKilos:96];
[person setHeightInMeters:1.8];
// Call the body mass index
float bmi = [person bodyMassIndex];
NSLog(@"person has a bmi of %f", bmi);
}
return 0; // Expected identifier or '('
} // Expected external declaration
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject {
float heightInMeters;
int weightInKilos;
}
// You will be able to set those instance variables using these methods
- (void)setHeightInMeters:(float)h;
- (void)setWeightInKilos:(int)w;
// This method calculates the body weight index
- (float)bodyMassIndex;
@end
Person.m
#import "Person.h"
@implementation Person
- (void)setHeightInMeters:(float)h{
heightInMeters = h;
}
- (void)setWeightInKilos:(int)w {
weightInKilos = w;
}
- (float)bodyMassIndex {
return weightInKilos/(heightInMeters * heightInMeters);
}
@end
謝謝;那就是訣竅。我使用的是Apple LLVM 3.0編譯器,所以我不確定它爲什麼會返回錯誤。 – pdenlinger
@pdenlinger:你是?呃,那個錯誤我期望它是GCC。似乎LLVM肯定能在這裏做得更好。你介意提交[bug報告](http://bugreport.apple.com)嗎? –
我不是註冊的Apple開發人員,我該如何保存?我可以發送一個鏈接到這個網頁到一個蘋果提交錯誤的電子郵件地址嗎? – pdenlinger