Re: Objective-C++ 2.0 - C++ valued properties
Re: Objective-C++ 2.0 - C++ valued properties
- Subject: Re: Objective-C++ 2.0 - C++ valued properties
- From: Jens Ayton <email@hidden>
- Date: Sun, 16 Mar 2008 06:17:11 +0100
Scott Thompson wrote:
I'm running into an odd error when trying to mix C++ and Objective-C
2.0 features. I wasn't sure if something along these lines is even
supposed to work so I thought I would ask.
What I tried to do was declare a property whose type was a C++
object. Something like (typed into mail so there may be errors):
class Vector3D
{
float x, y, z;
// Vector3D declarations here
};
@interface Object3D
{
Vector3D position;
}
@property (assign) Vector3D position;
@end
What I've discovered is that when I set the value of the property:
myObject.position = Vector3D(1.0, 2.0, 3.0)
Or something like that, that the value of the position property does
not change.
...
P.S. It would get even weirder if there was an operator= for the
Vector3D class. This code would have to do something like call the
operator, then go back and do the property key-value coding. What
would "setPosition:" do in that case.
Given the semantics of properties, I'd expect the following three
functions to generate identical code, with an C++ operator funniness
happening exactly as in the last case (which is plain C++ apart from
@selector()):
static void Test1(TestClass *obj, Vector3D v)
{
obj.position = v;
}
static void Test2(TestClass *obj, Vector3D v)
{
[obj setPosition:v];
}
static void Test3(TestClass *obj, Vector3D v)
{
typedef void (*SetPositionIMP)(id self, SEL _cmd, Vector3D
position);
((SetPositionIMP)objc_msgSend)(obj, @selector(setPosition:), v);
}
In a quick test, I find Test2 and Test3 compile to identical code, but
Test1 does some extra busywork that doesn't seem to accomplish
anything at first glance. However, all three cause setPosition: to be
called with the specified Vector3D, so the problem would seem to be
with your setPosition: (or the synthesized setPosition:, as the case
may be).
--
Jens Ayton
Sed quis custodiet ipsos custodes?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden