I have a question about binary compatibility. I have class A, which includes a public method foo(), and an attribute string _foo;
const string foo() {return _foo;}
When I changed to
const string& foo(){return _foo;}
Is it still binary compatible? Thanks for your help!
Returning a copy of a string will essentially do something like this:
string s = foo();
will, when the compiler generates machine code, appear similar to:
string s;
foo(&s);
Naturally, if you change the type of the return type, the pointer to s
needs to be appropriately modified. So no, you can't change the return type and maintain binary compatibility (and it will almost certainly not even compile, as the signature of the function has changed -> differnet mangled name -> "undefined reference").