目标c缺少方法声明的上下文

时间:2014-05-22 12:45:15

标签: objective-c methods method-call

int main (int argc, const char * argv[])
 {
     @selector(grades);

 }

-(int)grades:(int)grade{
    printf("Please write down your grade:");  
    scanf("%d", &grade);/*the grade value written has assigned to grade parameter*/   
    printf("\n");

    if((grade > 100) || (grade <0)){/*This is a warning range of grades */
    printf("Warning!!\nYour grade is out of range\nPlease write a NUMBER between 0-100\n");
}
else{/*The grade ranges are defined*/
    if((0<=grade) && (grade<=20))
        NSLog(@"Your letter grade is : F\nyou failed\n");/*NSLog has been used insted of printf*/
    if((21<=grade) &&(grade<=40))
        NSLog(@"Your letter grade is : D\nTry again\n");
    if((41<=grade) && (grade<=60))
        NSLog(@"your letter grade is : C\nNot bad\n");
    if((61<=grade)&&(grade<=80))
        NSLog(@"Your letter grade is : B\nWell Done\n");
    if((81<=grade)&&(grade<=100))
        NSLog(@"your letter grade is : A\nGreat !!\n");
}
return 0;
}

我在方法声明中遇到问题我想我已经检查了它 我找不到任何错误 如果你们中的任何人能帮助我,那就太好了。 谢谢

2 个答案:

答案 0 :(得分:1)

该方法没有上下文。该方法被声明为对象的实例方法-,但是没有与之关联的类。因此,在什么情况下声明该方法是未知的。

对于您的案例使用,

            int grade (int grade)
            {
                printf("Please write down your grade:");
                scanf("%d", &grade);/*the grade value written has assigned to grade parameter*/
                printf("\n");

                if((grade > 100) || (grade <0)){/*This is a warning range of grades */
                    printf("Warning!!\nYour grade is out of range\nPlease write a NUMBER between 0-100\n");
                }
                else{/*The grade ranges are defined*/
                    if((0<=grade) && (grade<=20))
                        NSLog(@"Your letter grade is : F\nyou failed\n");/*NSLog has been used insted of printf*/
                    if((21<=grade) &&(grade<=40))
                        NSLog(@"Your letter grade is : D\nTry again\n");
                    if((41<=grade) && (grade<=60))
                        NSLog(@"your letter grade is : C\nNot bad\n");
                    if((61<=grade)&&(grade<=80))
                        NSLog(@"Your letter grade is : B\nWell Done\n");
                    if((81<=grade)&&(grade<=100))
                        NSLog(@"your letter grade is : A\nGreat !!\n");
                }
                return 0;
            }

            int main(int argc, const char * argv[])
            {

                grade(0);
            }

答案 1 :(得分:1)

我的印象是“缺少方法声明的上下文”(MCFMD)的问题已完全理解从不

相关帖子为某些特定情况提供了一些解决方案,但至少在90%的情况下无法解决任何解释或一般方法,例如:

  

问: objective-c“缺少方法声明的上下文” - 5月13日由user3631024询问

     

问:使用构造函数的方法声明缺少上下文” - 由user2789992询问第18页

     

问:缺少方法声明的上下文用于重写的描述方法 -asked apr 26 '12 by pdenlinger

与此同时,一些人抱怨说他们认为MCFMD问题已经成熟并得到了充分解决......我在一段时间内在代码中与33 MCFMD作战,这更像是在黑暗中拍摄。我希望那些对MCFMD问题有更多了解的人分享他们宝贵的知识或任何理解...... 非常感谢你的关注!