Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at auto_gcroot::operator auto_gcroot.
Type-cast operator between auto_gcroot and compatible types.
Syntax
template<typename _other_type>
operator auto_gcroot<_other_type>();
Return Value
The current auto_gcroot cast to auto_gcroot<_other_type>.
Example
// 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!
Requirements
Header file <msclr\auto_gcroot.h>
Namespace msclr