We all know how sparsely documented Objective-C++ is. I can't find anything on this, but I'm also finding it hard to find suitable unambiguous search terms. So, Stackoverflow to the rescue (I hope)!
I have a C++ class that I have an instance of within an Objective-C(++) class (and I have the project setting enabled for constructors/ destructors to be called).
This all works fine until I try to expose the instance via a @synthesize
d property. I make it an assign
property (as Obj-C retain counting is not applicable). The property appears to work except when I set the instance I would expect the copy constructor to be involved.
What I actually see is that a temporary instance is created (the copy constructor on that is invoked) - which is all expected. But the copy constructor on the ivar instance is not called. The values are "magically" set. I'm presuming that the @synthesize
d code is doing something like a memcpy
as the final step. This is fine for C struct
s, but not so helpful for C++ class
es where the correctness of the code depends on the copy constructors and assignment operators being called appropriately.
Has anyone looked into this in any more depth, got it working, or confirmed that it is not possible to hold C++ objects as ivars in an Obj-C(++) class and have copy constructors called by @synthesize
d property setters?
(I can post sample code for all this if necessary - but even the minimal version is a screenful or so).