共用方式為


auto_gcroot::operator auto_gcroot

之間的型別轉型運算子auto_gcroot和相容的型別。

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

傳回值

目前的auto_gcroot轉換成auto_gcroot<_other_type>。

範例

// 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();
}
  
  

需求

標頭檔 <msclr\auto_gcroot.h>

Namespace msclr

請參閱

其他資源

auto_gcroot Members