Inheritance difficulty...
Inheritance difficulty...
- Subject: Inheritance difficulty...
- From: Adrian Bool <email@hidden>
- Date: Wed, 30 Oct 2002 10:04:30 +0000
Hi there,
I'm relatively new ot ObjC, being more used to C++, however I'm wondering
if anyone could save me from throwing this pretty iMac out of my 4th story
window!! ;-)
I am trying to sub-class NSFilehandle to produce a new Class, INSocket.
Right now all I am trying to do is create my subclass and pass on the
initialiaser (almost) without alteration with the intent that my INSocket
should, for now, behave exactly like an NSFileHandle. My only change is
to alter the initialiser name such that it as the word 'Socket' in - so I
can tell which function (mine or superclass') the run-time system moans
about...
My code is (in .h and .m files as appropriate..),
#import <Foundation/Foundation.h>
@interface INSocket : NSFileHandle
- (id)initSocketWithFileDescriptor:(int)fd closeOnDealloc:(BOOL)closeopt;
@end
@implementation INSocket
- (id)initSocketWithFileDescriptor:(int)fd closeOnDealloc:(BOOL)closeopt
{
NSLog(@"in initsocketWithFileDescriptor");
[super initWithFileDescriptor: fd closeOnDealloc: closeopt] ;
return self ;
}
@end
To use my shiny new Class, I first create a socket (s) using normal Unix
calls and then call,
INSocket * nss ;
nss = [INSocket alloc] ;
NSLog(@"alloced nss");
[nss initSocketWithFileDescriptor: s closeOnDealloc: YES] ;
NSLog(@"inited nss");
This compiles fine, with no warnings.
When run, I get the following output in PB's run window,
2002-10-30 09:17:19.721 iNews[1382] alloced nss
2002-10-30 09:17:19.721 iNews[1382] in initsocketWithFileDescriptor
2002-10-30 09:17:19.721 iNews[1382] *** -[INSocket
initWithFileDescriptor:closeOnDealloc:]: selector not recognized
2002-10-30 09:17:19.726 iNews[1382] *** -[INSocket
initWithFileDescriptor:closeOnDealloc:]: selector not recognized
And the socket is created and a connection is made to the remote machine
successfully. My initSocketWithFileDescriptor:closeOnDealloc: method does
get called (as you can see by the NSLog line). The program then seems to
hang on my call to [super closeOnDealloc: fd closeOnDealloc: closeopt].
I can only presume that the warning/error 'selector not recognized' has
something to do with my hang...
If I write the program without my object and just crate my socket then a
NSFileHandle directly, there is no hang...
I notice that in NSFileHandle's .h file, that it's method
closeOnDealloc:closeOnDealloc:
is defined within a 'Category' - in this case
(NSFileHandlePlatformSpecific). Perhaps this has some bearing on my
troubles??
Any hints on where I am going wrong would be deeply appreciated.
Regards,
aid
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.