How to use smart pointers as Objective-C fields

Ruslan Zasukhin sunshine at public.kherson.ua
Thu Aug 3 10:03:13 CDT 2006


On 8/3/06 3:38 AM, "Matthew Jew" <mjew at icnc.com> wrote:

Hi Matthew, 

> I made an Objective C class that acts as a sort of wrapper from the
> old FBL_ArraySet.
> It was defined like this:
> 
> @interface PVArraySet : NSObject <NSCopying, NSCoding>
> {
> FBL_ArraySet *myArray;
> }
> 
> 
> Now, with the new Smart Pointers, I have modified it to be like this:
> 
> @interface PVArraySet2 : NSObject <NSCopying, NSCoding>
> {
> ArraySet_Ptr myArray;
> }
> 
> However, when I do that, I get the following compilation warnings:
> 
> /Volumes/Alpha2/Dev-NuPV/PVReplicator2/../Common-Classes/Classes/
> PVArraySet2.h:18: warning: type `ArraySet_Ptr' has a user-defined
> constructor
> /Volumes/Alpha2/Dev-NuPV/PVReplicator2/../Common-Classes/Classes/
> PVArraySet2.h:18: warning: type `ArraySet_Ptr' has a user-defined
> destructor
> /Volumes/Alpha2/Dev-NuPV/PVReplicator2/../Common-Classes/Classes/
> PVArraySet2.h:18: warning: C++ constructors and destructors will not
> be invoked for Objective-C fields
> 
> 
> My question is this: will this Objective C class work properly, given
> that the Smart Pointer's constructors and destructors will not be
> invoked?

no

> If not, how am I supposed to address this?

We have had similar problems in VNET.

Solution is:

* continue to use simple pointers
     FBL_ArraySet *myArray;

* use AddRef() and Release

PVArraySet()
{   
    myArray = pSet.get();
    pSet->AddRef();
}


~PVArraySet()
{
    myArray->Release();
}





-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list