, ,
class foo{
private:
string str;
public:
foo operator = (string s){
str = s;
}
};
, , foo.
,
foo & operator = ( const std::string &s){
str = s;
return *this;
}
, , .
, . ,
foo();
,
for( const foo & );
foo a = "this initialization throwing an error";
, foo, a. . foo. , , .
error: 'const char [38]' 'foo'
const char[33] - .
foo b;
b = "but assignment after declaration is working fine";
b foo, , , . , str std::string, . , std::string .