Re: warning: local declaration hides instance variable
Re: warning: local declaration hides instance variable
- Subject: Re: warning: local declaration hides instance variable
- From: Tron Thomas <email@hidden>
- Date: Mon, 03 Sep 2007 10:33:02 -0700
If I do something equivalent in C++ like:
class Value
{
private:
int value;
public:
void SetValue(int value)
{
this->value = value;
};
};
I don't get any warnings. What is the reason for the warning in
Objective-C and no warning in C++?
Shawn Erickson wrote:
On Sep 3, 2007, at 10:13 AM, Tron Thomas wrote:
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
- (void)setAmount:(int)amount
{
self->amount = amount;
}
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
This results indicates that the warning is wrong.
No the warning isn't wrong.
The instance variable was assigned the proper value.
Well only because you are accessing the ivar via struct reference.
-Shawn
_______________________________________________
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