Jump to content

Objective C/C++ Pointers using . ?


2 posts in this topic

Recommended Posts


I'm starting to get more comfortable using Objective C++ coming from a C/C++ background.

I'm just realizing one of the things that has been confusing me, so I'm wondering if anyone can help me figure it out.

Basically what I realized is that pointers in Objective C++ or Objective C can have . operators (?) to access members, but in C and C++, pointers need -> to access members. I notice that when I access my C and C++ members of objective C++ classes (?), I have to use . to access Objective C++ members (properties?), while simultaneously using -> to access C and C++ members. What is going on with this? What is the meaning of using a . on a pointer in Objective C++? Do I simply have to make pointers of objective C++ class pointers to get objects the way I think of them in C++?

Thanks in advance,


Link to comment
Share on other sites

In objective C, pointers uses the asterisk * to denote a pointer. The period is used when you have properties of an object for instance:




@interface MyClass : NSObject

NSObject *Cars;  // an object car

int weight,speed; // just two integer values

// declare the properties of the Class
@property(nonatomic) int weight;
@property(nonatomic) int speed;


Then in your implementation file aka the .m file


@implementation MyClass

@synthesize weight,speed; // must synthesize properties you create

// now you may use the properties

 Car.weight = 1593;
 Car.speed = 155;


Link to comment
Share on other sites


  • Create New...