In a dll, suppose we have a class member function to return a string member:
string get_name() {return string;}
In another module, for example, the main application try to use the function to get the name string:
myobj.get_name();
This seems to be perfect OK, but in reality, this will cause memory access violation and program crash. The reason:
When call myobj.get_name(), inside the DLL, it will create a temp object in the dll memory space. After the call is done, the main application tries to delete the temporary object, but the temp object is not inside the main application memory space and it is not allowed.
To fix this, change the member function to:
const string& get_name() {return name;}