Bagikan melalui


fungsi pertukaran (auto_gcroot)

Tukar objek antara satu auto_gcroot dan lainnya.

Sintaks

template<typename _element_type>
void swap(
   auto_gcroot<_element_type> & _left,
   auto_gcroot<_element_type> & _right
);

Parameter

_Kiri
Sebuah auto_gcroot.

_Kanan
Lain auto_gcroot.

Contoh

// msl_swap_auto_gcroot.cpp
// compile with: /clr
#include <msclr\auto_gcroot.h>

using namespace System;
using namespace msclr;

int main() {
   auto_gcroot<String^> s1 = "string one";
   auto_gcroot<String^> s2 = "string two";

   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",
      s1->ToString(), s2->ToString() );
   swap( s1, s2 );
   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",
      s1->ToString(), s2->ToString() );
}
s1 = 'string one', s2 = 'string two'
s1 = 'string two', s2 = 'string one'

Persyaratan

File header<msclr\auto_gcroot.h>

Namespace msclr

Lihat juga

auto_gcroot
auto_gcroot::swap