discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically instantiating a class


From: Erik M. Buck
Subject: Re: dynamically instantiating a class
Date: Fri, 31 Aug 2001 15:03:38 -0500

Try the following:

clazz = NSClassFromString ( @"Platform" );
p = (id <PeerGroup>) [[clazz alloc] init];
if ( [p conformsTo:@protocol(PeerGroup)] )
   NSLog ( @"Yes, this is indeed a PeerGroup" );
else
   NSLog ( @"No, this isn't a PeerGroup" );

If you MUST use NSAllocateObject() the write
p = (id <PeerGroup>) NSAllocateObject( clazz, 0, NULL);  // DO NOT
DEREFERNCE THE clazz variable

----- Original Message -----
From: "Aurelien" <address@hidden>
To: <address@hidden>
Sent: Friday, August 31, 2001 12:09 PM
Subject: dynamically instantiating a class


I'm trying to dynamically instantiate a class like so:

Class * clazz;
id <PeerGroup> p;

clazz = NSClassFromString ( @"Platform" );
p = (id <PeerGroup>) NSAllocateObject( *clazz, 0, NULL);
if ( [p conformsTo:@protocol(PeerGroup)] )
   NSLog ( @"Yes, this is indeed a PeerGroup" );
else
   NSLog ( @"No, this isn't a PeerGroup" );

Guess the result...

What's wrong ?

Aurélien

_______________________________________________
Discuss-gnustep mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/discuss-gnustep





reply via email to

[Prev in Thread] Current Thread [Next in Thread]