First of all, I'm a beginner in objective-C. At the moment I'm trying to resolve the following problem:
@interface Animal : NSObject {
@private
NSString* m_name;
}
-(Animal*) initName:(NSString*)name;
-(void) printName;
@implementation Animal
-(Animal*) initName:(NSString*)name {
self = [super init];
m_name = name;
return self;
}
-(void) printName {
NSLog(@"%s", m_name);
}
@end
@interface Bird : Animal {
}
-(Bird*) initName:(NSString*)name;
@implementation Bird
-(Bird*) initName:(NSString*)name {
self = [super initName:name];
return self;
}
@end
int main() {
Animal* bird = [[Bird alloc] initName:@"abird"]; // warning: assignment from distinct Objective-C type
[bird printName]; // prints invalid letters
[bird release];
}
I want to propagate the constructor argument name
to the superclass, but it doesn't work.
I also tried to print the name inside the constructor without any success.
All necessary headers are included. The warning warning: assignment from distinct Objective-C type [enabled by default]
when creating the child class object is the only warning I get.
Does anyone has an idea how I could solve this problem?
Greetings Dan