string m = "dds"; string* temp = new string; 

How to use the copy constructor from string to assign the value to which temp refers to the value of m ?

ps Do I understand correctly that when dereferencing temp rvalue returns? which change does not affect the contents of the variable pointed to by temp ?

  • The result of the dereference (the built-in unary operator * ) is always an lvalue. - AnT

1 answer 1

If you are interested in the copy constructor , then you should be upset - to assign (and not create) with the help of the constructor - nonsense.

I think you just want

 string * temp = new string(m); 

Here the copy constructor is used when creating the object pointed to by temp .

If assigned - using copy assignment :

 *temp = m; 

No, wrong. *temp is quite lvalue. See for yourself - https://ideone.com/ZkagqR