次の方法で共有


auto_handle::operator auto_handle

auto_handle と互換性のある型の間の型キャスト演算子。

template<typename _other_type>
operator auto_handle<_other_type>();

戻り値

auto_handle<_other_type> に対する現在の auto_handle のキャスト。

使用例

// 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!

必要条件

ヘッダー ファイル <msclr\auto_handle.h>

名前空間 msclr

参照

概念

auto_handle Members