次の方法で共有


auto_gcroot::operator auto_gcroot

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

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

戻り値

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

使用例

// msl_auto_gcroot_op_auto_gcroot.cpp
// compile with: /clr
#include <msclr\auto_gcroot.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_gcroot<ClassB^> b = gcnew ClassB("first");
   b->PrintHello();
   auto_gcroot<ClassA^> a = (auto_gcroot<ClassA^>)b;
   a->PrintHello();
}

Hello from first B!
Hello from first A!

必要条件

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

名前空間 msclr

参照

概念

auto_gcroot Members