• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
warning: local declaration hides instance variable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: warning: local declaration hides instance variable
      • From: Wincent Colaiuta <email@hidden>
    • Re: warning: local declaration hides instance variable
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: Adding Help
  • Next by Date: Re: warning: local declaration hides instance variable
  • Previous by thread: Re: Tricky "inline-assembly/C++ template" issue
  • Next by thread: Re: warning: local declaration hides instance variable
  • Index(es):
    • Date
    • Thread