auto_ptr in STL
int main( void )
{
auto_ptr<int> test, test2( new int( 5 ) );
// 1) succeed
test = test2;
// 2) complie error
test = auto_ptr<int>( new int( 5 ) );
// 3) compile error
test = new int( 5 );
cout<<(*test)<<endl;
return 0;
}
其中编译错误为
2)
Could not find a match for 'auto_ptr<int>::operator =(auto_ptr<int>)'
3)
Could not find a match for 'auto_ptr<int>::operator =(int *)'
我想如果这个auto_ptr如果只能在初始化时赋值,那好像就没有什么实用了。
第3 行的错误我可以理解,是没有相应的重载操作符。
但第2 行就有点奇怪了,毕竟第1 行执行成功的,希望高手指点??