Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Umwandlungen von auto_ptr zu auto_ptr_ref.
template<class Other>
operator auto_ptr_ref<Other>( ) throw( );
Rückgabewert
Der Typumwandlungsoperator gibt auto_ptr_ref<Andere> zurück (*this).
Beispiel
// auto_ptr_op_auto_ptr_ref.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>
using namespace std;
class C{
public:
C(int _i) : m_i(_i){
}
~C(){
cout << "~C: "<< m_i <<"\n";
}
C &operator =(const int &x){
m_i = x;
return *this;
}
int m_i;
};
void f(auto_ptr<C> arg ){
};
int main()
{
const auto_ptr<C> ciap ( new C(1) );
auto_ptr<C> iap ( new C(2) );
// Error: this implies transfer of ownership of iap's pointer
// f(ciap);
f(iap); // compiles, but gives up ownership of pointer
// here, iap owns a destroyed pointer so the following is bad:
// *iap = 5; // BOOM
cout << "main exiting\n";
}
Anforderungen
Header: <memory>
Namespace: std