Hi All,
I am just starting out in Objective-C programming, following the Kochan book "Programming in Objective-C 2.0".
I'm sure this has a simple answer...
The following code has me scratching my head - I cannot see why the variables X & Y don't get printed to the screen in the console window.
Can some please assist me?
Any help much appreciated!
Thanks
End result:
I am just starting out in Objective-C programming, following the Kochan book "Programming in Objective-C 2.0".
I'm sure this has a simple answer...
The following code has me scratching my head - I cannot see why the variables X & Y don't get printed to the screen in the console window.
Can some please assist me?
Any help much appreciated!
Thanks
Code:
// Class called XYPoint that will hold a Cartesian coordinate (x,y), where x and y are integers.
#import <Foundation/Foundation.h>
// ---- @interface section ----
@interface XYPoint : NSObject
{
int xCoord;
int yCoord;
}
- (void) setX: (int) x;
- (void) setY: (int) y;
- (int) getX;
- (int) getY;
@end
// ---- @implementation section ----
@implementation XYPoint
- (void) setX: (int) x
{
xCoord = x;
}
- (void) setY: (int) y
{
yCoord = y;
}
- (int) getX
{
return xCoord;
}
- (int) getY
{
return yCoord;
}
@end
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
XYPoint *myXYPoint = [[XYPoint alloc] init];
// Set X Y points
[myXYPoint setX: 7];
[myXYPoint setY: 42];
// Display the X Y points
NSLog (@"The value of the x point is: ", [myXYPoint getX]);
NSLog (@"The value of the y point is: ", [myXYPoint getY]);
[myXYPoint release];
[pool drain];
return 0;
}
End result:
Code:
[Session started at 2009-02-20 10:22:20 +1100.]
2009-02-20 10:22:21.017 ch3ex7[97725:10b] The value of the x point is:
2009-02-20 10:22:21.018 ch3ex7[97725:10b] The value of the y point is:
The Debugger has exited with status 0.