• 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
Re: only defined for abstract class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: only defined for abstract class


  • Subject: Re: only defined for abstract class
  • From: Francis Derive <email@hidden>
  • Date: Thu, 6 Oct 2005 09:47:15 +0200


On Oct 4, 2005, at 9:29 PM, Pontus Ilbring wrote:

On 10/4/05, Francis Derive <email@hidden> wrote:

How do you understand that ? Can't "addObject:" be found in the super
class of "SousClasse" - that is NSMutableArray ?

@interface SousClasse : NSMutableArray {
     Class laClasse;
}
- (id) init;
- (id) initWithClass:(Class) aClass;
@end


NSMutableArray is an abstract class.

http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaObjects/Articles/ClassClusters.html



I am stick to reading this Class Cluters documentation, and it is not so easy to do in practice :


@interface SousClasse : NSMutableArray { Class laClasse; }

+ sousClasse;
+ sousClasseWithClass:(Class) aClass;
- (id) init;
- (id) initWithClass:(Class) aClass;
- (unsigned) count;
- (id) objectAtIndex:(unsigned) index;

@end

My SousClasse is - as an exercise - to built NSMutableArrays the elements of which belong to a specific "type"/class.

From what I have read, here I override the 2 inherited "primitive" methods -count and -objectAtIndex:

The SousClasse's -count can't be so much different than NSMutableArray's and NSArray's -count, but there is a problem here, because I don't get NSMutableArray as [super className] but SousClasse !


- (unsigned) count { NSLog(@"*** count %@", [super className]); return [super count]; }



And I overrides objectAtIndex:, somehow :


- (id) objectAtIndex:(unsigned) index {
theObject = [super objectAtIndex:index];
if (![[theObject class] isEqual:laClasse]) {
[NSException raise:NSInternalInconsistencyException format:@"*** class name %s of object %@ is not allowed, give it %s", [theObject className], theObject, [laClasse className]];
} else {
return theObject;
}


}


The main is only this :

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSMutableArray *myArray1 = [[NSMutableArray alloc] init];
SousClasse *myArray2 = [[SousClasse alloc] init]; // From the implemented "init", then myArray2 should be of the default class "NSString".


    [myArray1 addObject:@"un"];
    NSLog(@"myArray1 a %d objets", [myArray1 count]);

//[myArray2 addObject:@"deux"];
NSLog(@"myArray2 a %d objets", [myArray2 count]); // count should be zero.


    [pool release];
    return 0;
}


[Session started at 2005-10-06 09:18:36 +0200.]
2005-10-06 09:18:36.993 Test[510] myArray1 a 1 objets
2005-10-06 09:18:37.037 Test[510] *** in count [super className] is SousClasse
2005-10-06 09:18:37.039 Test[510] *** Uncaught exception: <NSInvalidArgumentException> *** -count only defined for abstract class. Define -[SousClasse count]!


Test has exited due to signal 5 (SIGTRAP).


****** Any more help is welcome indeed !


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: only defined for abstract class
      • From: "Mark Munz (DevList)" <email@hidden>
    • Re: only defined for abstract class
      • From: Nick Zitzmann <email@hidden>
References: 
 >only defined for abstract class (From: Francis Derive <email@hidden>)
 >Re: only defined for abstract class (From: Pontus Ilbring <email@hidden>)

  • Prev by Date: Re: awakeFromNib not called
  • Next by Date: NSKeyedArchiver UTF-8 problems
  • Previous by thread: Re: only defined for abstract class
  • Next by thread: Re: only defined for abstract class
  • Index(es):
    • Date
    • Thread