2011-11-14 38 views
1

我得到這個問題,我在我的主要文件都評論:預計標識符或 '(' 失蹤

#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 

回答

6

您的程序在return 0;之前有一個流氓}。錯誤相當具有誤導性。您可能想要swi切換到使用LLVM而不是GCC(這會讓你更快地編譯,而不僅僅是更好的錯誤)。

+0

謝謝;那就是訣竅。我使用的是Apple LLVM 3.0編譯器,所以我不確定它爲什麼會返回錯誤。 – pdenlinger

+0

@pdenlinger:你是?呃,那個錯誤我期望它是GCC。似乎LLVM肯定能在這裏做得更好。你介意提交[bug報告](http://bugreport.apple.com)嗎? –

+0

我不是註冊的Apple開發人員,我該如何保存?我可以發送一個鏈接到這個網頁到一個蘋果提交錯誤的電子郵件地址嗎? – pdenlinger

0

你的主函數底部有一個額外的大括號。正好在「返回0」之上線。

0

在您的主要功能返回之前,什麼是右括號?我認爲你關閉了很多。