Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- @class MyNum;
- @class MyFloat;
- @class MyInt;
- @interface MyNum : NSObject
- - (id)initWithFloat:(float)value;
- - (id)initWithInt:(int)value;
- - (void)print;
- @end
- @interface MyFloat : MyNum
- @property float value;
- - (id)initWithFloat:(float)value;
- @end
- @interface MyInt : MyNum
- @property int value;
- - (id)initWithInt:(int)value;
- @end
- @implementation MyInt
- @synthesize value = _value;
- - (id)initWithInt:(int)value {
- if ((self = [super init]))
- {
- self.value = value;
- }
- return self;
- }
- - (void)print {
- NSLog(@"%d",self.value);
- }
- @end
- @implementation MyFloat
- @synthesize value = _value;
- - (id)initWithFloat:(float)value {
- if ((self = [super init]))
- {
- self.value = value;
- }
- return self;
- }
- - (void)print {
- NSLog(@"%f",self.value);
- }
- @end
- @implementation MyNum
- - (id)initWithFloat:(float)value {
- return [[MyFloat alloc] initWithFloat:value];
- }
- - (id)initWithInt:(int)value {
- return [[MyInt alloc] initWithInt:value];
- }
- - (void)print {
- [self doesNotRecognizeSelector:_cmd];
- }
- @end
- int main (int argc, const char * argv[])
- {
- @autoreleasepool {
- for (int i = 0; i < 10000; i++) {
- // Test 1
- MyNum *floatValue = [[MyNum alloc] initWithFloat:32.0];
- MyNum *intValue = [[MyNum alloc] initWithInt:32];
- // Test 2
- // MyFloat *floatValue = [[MyFloat alloc] initWithFloat:32.0];
- // MyInt *intValue = [[MyInt alloc] initWithInt:32];
- [floatValue print];
- [intValue print];
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment