转换在 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>
命名空间 msclr