title
auto_handle::operator auto_handle | Microsoft Docs
ms.custom
ms.date
11/04/2016
ms.technology
ms.topic
reference
f1_keywords
msclr.auto_handle.operator auto_handle
operator auto_handle
msclr::auto_handle::operator auto_handle
auto_handle.operator auto_handle
auto_handle::operator auto_handle
dev_langs
helpviewer_keywords
ms.assetid
2f8b35d1-2783-4d91-b6fb-eae551270fb8
author
mikeblome
ms.author
mblome
ms.workload
auto_handle::operator auto_handle
Type-cast operator between auto_handle and compatible types.
template<typename _other_type>
operator auto_handle<_other_type>();
The current auto_handle cast to auto_handle<_other_type>.
// msl_auto_handle_op_auto_handle.cpp
// compile with: /clr
#include <msclr\auto_handle.h>
using namespace System;
using namespace msclr;
ref class ClassA {
protected:
String^ m_s;
public:
ClassA( String^ s ) : m_s( s ) {}
virtual void PrintHello() {
Console::WriteLine( "Hello from {0} A!", m_s );
}
};
ref class ClassB : ClassA {
public:
ClassB( String ^ s) : ClassA( s ) {}
virtual void PrintHello() new {
Console::WriteLine( "Hello from {0} B!", m_s );
}
};
int main() {
auto_handle<ClassB> b = gcnew ClassB("first");
b->PrintHello();
auto_handle<ClassA> a = (auto_handle<ClassA>)b;
a->PrintHello();
}
Hello from first B!
Hello from first A!
Header file <msclr\auto_handle.h>
Namespace msclr
auto_handle Members