次の方法で共有


auto_handle::swap

別の auto_handle とオブジェクトをスワップします。

void swap(
   auto_handle<_element_type> % _right
);

パラメータ

  • _right
    オブジェクトをスワップする auto_handle。

使用例

// msl_auto_handle_swap.cpp
// compile with: /clr
#include <msclr\auto_handle.h>

using namespace System;
using namespace msclr;

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

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

s1 = 'string one', s2 = 'string two'
s1 = 'string two', s2 = 'string one'

必要条件

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

名前空間 msclr

参照

概念

auto_handle Members

swap 関数 (auto_handle)