auto_handle : : auto_handle
Constructeur auto_handle.
auto_handle();
auto_handle(
_element_type ^ _ptr
);
auto_handle(
auto_handle<_element_type> % _right
);
template<typename _other_type>
auto_handle(
auto_handle<_other_type> % _right
);
Paramètres
_ptr
Objet à posséder._right
auto_handle existant.
Exemple
// msl_auto_handle_auto_handle.cpp
// compile with: /clr
#include "msclr\auto_handle.h"
using namespace System;
using namespace msclr;
ref class RefClassA {
protected:
String^ m_s;
public:
RefClassA(String^ s) : m_s(s) {
Console::WriteLine( "in RefClassA constructor: " + m_s );
}
~RefClassA() {
Console::WriteLine( "in RefClassA destructor: " + m_s );
}
virtual void PrintHello() {
Console::WriteLine( "Hello from {0} A!", m_s );
}
};
ref class RefClassB : RefClassA {
public:
RefClassB( String^ s ) : RefClassA( s ) {}
virtual void PrintHello() new {
Console::WriteLine( "Hello from {0} B!", m_s );
}
};
int main()
{
{
auto_handle<RefClassA> a(gcnew RefClassA( "first" ) );
a->PrintHello();
}
{
auto_handle<RefClassB> b(gcnew RefClassB( "second" ) );
b->PrintHello();
auto_handle<RefClassA> a(b); //construct from derived type
a->PrintHello();
auto_handle<RefClassA> a2(a); //construct from same type
a2->PrintHello();
}
Console::WriteLine("done");
}
Configuration requise
Fichier d'en-tête <msclr\auto_handle.h>
Espace de noms msclr