我在主文件中发现了这个问题:
#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
答案 0 :(得分:6)
}
之前,您的计划中有一个迷路return 0;
。该错误颇具误导性。您可能希望切换到使用LLVM而不是GCC(这样可以加快编译速度,而不仅仅是更好的错误)。
答案 1 :(得分:0)
主要功能底部有一个额外的近距离支撑。正好在“返回0”之上线。
答案 2 :(得分:0)
在主要功能返回之前,结束括号是做什么的?我认为你关闭了1对多。