Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > Re: Dynamic pro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 1007 of 1041
Post > Topic >>

Re: Dynamic properties in abstract cl*****

by FreeMan <basurero@[EMAIL PROTECTED] > Jul 23, 2008 at 10:01 PM

Thank you, I think that this is a well known mistake that I forgot.

On 2008-07-22 00:51:57 +0200, Greg Parker <gparker@[EMAIL PROTECTED]
> said:

> FreeMan <basurero@[EMAIL PROTECTED]
> writes:
>> Hello, AFAIK an im****tant purpose of the @[EMAIL PROTECTED]
 compiler directive is
to
>> allows for the existence of polimorfic properties where their value is
>> defined in subcl*****. However, I found the issue below which I think
that
>> is inconsistent with this purpose. Specifically in this example, it's
not
>> possible to use a nCols @[EMAIL PROTECTED]
 property because its instance variable
is
>> not defined yet in the following Matrix abstract class:
>> 
>> #im****t <Foundation/Foundation.h>
>> 
>> @[EMAIL PROTECTED]
 Matrix : NSOperation {
>> const NSData* elements;
>> }
>> @[EMAIL PROTECTED]
 (retain) const NSData* elements;
>> @[EMAIL PROTECTED]
 (assign) NSUInteger nRows;
>> @[EMAIL PROTECTED]
 (assign) NSUInteger nCols;
>> - (NSInteger)elementAtRow:(NSUInteger)row col:(NSUInteger)col;
>> - (void)dealloc;
>> @[EMAIL PROTECTED]
>> 
>> #im****t "Matrix.h"
>> 
>> @[EMAIL PROTECTED]
 Matrix
>> @[EMAIL PROTECTED]
 elements;
>> @[EMAIL PROTECTED]
 nRows;
>> @[EMAIL PROTECTED]
 nCols;
>> - (NSInteger)elementAtRow:(NSUInteger)row col:(NSUInteger)col {
>> NSInteger* array = (NSInteger*) [elements bytes];
>> // It fails (error: 'nCols' undeclared (first use in this function)
>> //return array[row*nCols+col];
>> // It works
>> return array[row*[self nCols]+col];
>> }
>> - (void)dealloc {
>> if (elements!=nil)
>> [elements release];
>> [super dealloc];
>> }
>> @[EMAIL PROTECTED]
>> 
>> In this example the method nCols has been declared in the prototype by
>> menas of the @[EMAIL PROTECTED]
 directive (and can be invoked), but has not been
>> implemented in this yet abstract class. HOWEVER, THE DOT SINTAX CANNOT
BE
>> USED. WHY?
> 
> Because your code is using the instance variable directly, not the
> property. There's no dot so that's not dot syntax.
> 
> These are ivar accesses:
>     nCols
>     self->nCols
> 
> These are property accesses:
>     self.nCols
>     [self nCols]
> 
> In the @[EMAIL PROTECTED]
 case there is no ivar, so you get an error. There is
> an ivar in the @[EMAIL PROTECTED]
 case as written above, but you generally
> shouldn't use the ivar directly because you're bypassing any atomicity
> and memory-management provided by the property.
 




 3 Posts in Topic:
Dynamic properties in abstract classes
FreeMan <basurero@[EMA  2008-07-21 12:54:21 
Re: Dynamic properties in abstract classes
Greg Parker <gparker@[  2008-07-21 15:51:57 
Re: Dynamic properties in abstract classes
FreeMan <basurero@[EMA  2008-07-23 22:01:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 11:09:08 CDT 2008.