warning: local declaration hides instance variable
warning: local declaration hides instance variable
- Subject: warning: local declaration hides instance variable
- From: Tron Thomas <email@hidden>
- Date: Mon, 03 Sep 2007 10:13:13 -0700
When I compile the following code:
#import <objc/Object.h>
#import <iostream>
@interface Value : Object
{
@private
int amount;
}
+ (Value*)valueWithAmount:(int)amount;
- (void)setAmount:(int)amount;
- (int)amount;
@end
@implementation Value
+ (Value*)valueWithAmount:(int)amount
{
Value* value = [[Value alloc] init];
if(nil != value){
value->amount = amount;
}
return value;
}
- (id)init
{
self = [super init];
if(nil == self){
return nil;
}
amount = 0;
return self;
}
- (void)setAmount:(int)amount
{
self->amount = amount;
}
- (int)amount
{
return amount;
}
@end
int main()
{
Value* value = [[Value alloc] init];
[value setAmount:42];
std::cout << "The value is " << [value amount] << ".\n";
return 0;
}
The class method valueWithAmount emits no warning, yet the instance
method setValue emits something like:
Value.mm: In function 'void -[Value setAmount:](Value*,
objc_selector*, int)':
Value.mm:38: warning: local declaration of 'amount' hides instance
variable
Furthermore when I run the program the output is:
The value is 42.
This results indicates that the warning is wrong. The instance
variable was assigned the proper value.
I'm wondering if this is a bug in the Objective-C compiler that
should be submitted to Apple.
What can people tell me about this warning?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden