智能指针不可以解引用赋值吗?
#include <iostream>#include <stdio.h>
#include <memory>
#include <string>
using namespace std;
int main( )
{
shared_ptr<string> p1 ;
string str = "abc" ;
if ( !p1 ) {
*p1 = str ;
}
cout<<*p1<<endl;
return 0 ;
}
2017-03-05 12:55
2017-03-05 15:23
2017-03-05 15:31
程序代码:#include <iostream>
#include <memory>
#include <string>
using namespace std;
int main( void )
{
shared_ptr<string> p = std::make_shared<string>();
*p = "abc";
cout << *p << endl;
return 0;
}
2017-03-06 08:29
程序代码:#include <iostream>
#include <stdio.h>
#include <malloc.h>
#include <memory>
#include <string>
using namespace std ;
int main( )
{
shared_ptr<string> p1 = make_shared<string>( ) ;
string str = "abc";
*p1 = str;
cout << (*p1) << endl;
return 0;
}
2017-03-08 10:38
2017-03-08 10:48
2017-03-08 10:57