Created
November 21, 2012 00:25
-
-
Save kvoss/4122247 to your computer and use it in GitHub Desktop.
alloc problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <objc/Object.h> | |
| #import <stdio.h> | |
| @interface Number: Object | |
| { | |
| @public | |
| int number; | |
| } | |
| - (void) printNum; | |
| - (id) init; | |
| @end | |
| ///////////////////////////////////// | |
| @implementation Number: Object | |
| - (void) printNum { | |
| printf("%d\n", number); | |
| } | |
| - (id) init{ | |
| self = [ super init ]; | |
| if (self) { | |
| number = 0; | |
| } | |
| return self; | |
| } | |
| @end | |
| int main(void) | |
| { | |
| //Number *myNumber = [Number new]; //[ Number new ]; // equal to [[Number alloc] init] | |
| Number *myNumber = [Number alloc]; | |
| myNumber = [myNumber init]; | |
| printf("lsajfks\n"); | |
| myNumber->number = 6; | |
| [myNumber printNum]; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment