c++ code
--------
#include "stdafx.h"
#include <iostream>
using namespace std;
class A
{
public:
static int a;
void set(int s)
{
a=s;
cout<<a<<endl;
}
void setData(int f)
{
cout<<"I am "<<f<<" years old!!!"<<endl;
}
};
int A::a=0;
int main()
{
A* ab=new A();
ab->set(10);
ab->setData(ab->a);
return 0;
}
I am trying to get the same output for this equivalent Objective C code.
main.m
---------
#import <Foundation/Foundation.h>
#import "A.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
A* ab = [[A alloc]init];
[ab set:10];
[ab setData:ab.a]; //getting error when passed ab->a or ab.a as an argument
[pool drain];
return 0;
}
A.h
---
#import <Foundation/Foundation.h>
@interface A : NSObject {
}
-(void)set:(int)s;
-(void)setData:(int)f;
@end
A.m
----
#import "A.h"
@implementation A
static int a;
-(void)set:(int)s
{
a=s;
NSLog(@"%d\n",a);
}
-(void)setData:(int)f
{
NSLog(@"%d",f);
}
@end
Error:Request for member 'a' in something not a structure or union.