智能指针不可以解引用赋值吗?
#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 ;
}
程序代码:#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;
}