Is the following piece of code valid?
class A { string m_name;
public:
string getName() { return m_name; }
}.....
printf("%s", object.getName().c_str())
......
where object.getName() returns a temporary string object.
The temporary string will persist for until printf()
completes so yes, it is safe and legal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With