USE OF UNDECLARED IDENTIFIER “SUM”

Glen Martin

Total Post:27

Points:191
Posted by  Glen Martin
 960  View(s)
Ratings:
Rate this:

I have repeated error 3rd time, but I could not found that what is mean of use of undeclared identifier ..

I wrote that program on function in objective-C

#import <Foundation/Foundation.h>

 

@interface Add:NSObject

 

/* method declaration */  - (int)add:(int)a andNum2:(int)b;

@end

@implementation Add

 

/* method returning the max between two numbers */  - (int)add:(int)a andNum2:(int)b {

/* local variable declaration */

int sum = a +b;

return sum;

}

@end

NSLog(@"sum is : %d", sum);// error this line    

  return 0;

}

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Use of undeclared identifier “sum”

    You can do like here:

    #import <Foundation/Foundation.h>

     

    @interface Add:NSObject {

      int sum;//Declare sum as global variable to access in class

     }

    - (int)add:(int)a andNum2:(int)b;

     @end

     

     @implementation Add

       - (int)add:(int)a andNum2:(int)b {

       sum = a +b;

       return sum;

    }

     

    @end

    NSLog(@"sum is : %d", sum);//Now Access global variable with in class.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!