Code:#include <iostream>
#include <string>
using namespace std;
class Class {
public:
string s;
string get_s()
{
static string _s = s;
return _s;
}
};
int main()
{
Class c;
c.s = "Hello world";
cout << c.get_s().c_str();
}
Printable View
Code:#include <iostream>
#include <string>
using namespace std;
class Class {
public:
string s;
string get_s()
{
static string _s = s;
return _s;
}
};
int main()
{
Class c;
c.s = "Hello world";
cout << c.get_s().c_str();
}
Nope...
In general, you should not have to worry about memory leak unless you use dynamic allocation.
Kuphryn