I'm trying out a test from an example in the book I am learning from to better understand it. Example, in Main I am trying to pass an argument to Object A that then gets passed through to Object B. Then back in Main I am trying to print the value from Object B. I am not getting any errors but a warning saying " passing argument 1 of setXvalue: makes pointer from integer without a cast". This error shows up in Main with this line [passTo setXvalue: 10];. The value that is returned in the Console is 0 when it should be 10
Here is the code
OBJECT A:
Object B:
Here is the code
Code:
#import <Foundation/Foundation.h>
#import "xholder.h"
#import "passer.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
xholder * holder = [[xholder alloc] init];
passer * passTo = [[passer alloc] init];
// setting the value 5 to int passit and print test
[passTo setPassit: 5];
NSLog(@"pass x = %i", passTo.passit);
[passTo setXvalue: 10];
NSLog(@"holder is %i", [holder print]);
[holder release];
[passTo release];
[pool drain];
return 0;
}
Code:
#import <Foundation/Foundation.h>
#import "xholder.h"
@interface passer : NSObject
{
int passit;
xholder *xvalue;
}
@property int passit;
-(void) setPassit: (int) a;
-(int) print;
-(void) setXvalue: (xholder *) b;
@end
Code:
#import "passer.h"
@implementation passer
@synthesize passit;
-(void) setPassit: (int) a
{
passit = a;
}
-(int) print
{
return passit;
}
-(void) setXvalue: (xholder *) b
{
xvalue = b;
}
@end
Code:
#import <Foundation/Foundation.h>
@interface xholder : NSObject
{
int xvalue;
}
@property int xvalue;
-(void) setXvalue: (int) xVal;
-(int) print;
@end
Code:
#import "xholder.h"
@implementation xholder
@synthesize xvalue;
-(void) setXvalue: (int) xVal
{
xvalue = xVal;
}
-(int) print
{
return xvalue;
}
@end