ref class Wrapper {
Native *pn;
public:
// resource acquisition is initialization
Wrapper( int val ) { pn = new Native( val ); }
// this will do our disposition of the native memory
~Wrapper(){ delete pn; }
void mfunc();
protected:
// an explicit Finalize() method—as a failsafe
!Wrapper() { delete pn; }
};
void f1()
{
// normal treatment of a reference type
Wrapper^ w1 = gcnew Wrapper( 1024 );
// mapping a reference type to a lifetime
Wrapper w2( 2048 ); // no ^ token !
// just illustrating a semantic difference
w1->mfunc();
w2.mfunc();
// w2 is disposed of here
}
//
// ... later, w1 is finalized at some point, maybe