c++ - What is the difference between these statements -


i have these 2 statements. difference between string(sample_string).erase(i,j) , sample_string.erase(i,j) ?

sample_string.erase(i,j) 

calls erase method on sample_string object (assuming instance of class implements method).


string(sample_string).erase(i,j) 

creates temporary instance of string class, calling string constructor using sample_string object initialization of string, , calls erase method on temporary object.


Comments