The main motivation is that preferring nonmember nonfriend functions helps keep classes as concise as possible. See Herb Sutter's article here: http://www.gotw.ca/publications/mill02.htm.
This article also contains the answer to the other part of your question, where to put the corresponding get function. It's a feature of C++ called Argument Dependent Lookup (ADL). From Herb Sutter, who calls it Koenig lookup although this name is controversial (see comments below):
Koenig lookup says that, if you supply a function argument of class
type, then to find the function name the
compiler is required to look, not just in the usual places like the
local scope, but also in the namespace (here NS) that contains the
argument's type.
Here's an example:
namespace MyNamespace {
class MyClass {... };
void func(MyClass);
}
int main(int aArgc, char* aArgv[]) {
MyNamespace::MyClass inst;
func(inst); // Ok, because Koenig says look in the argument's namespace for func
}
So in short, you just declare the get function in the same namespace as your class.
Be aware that this doesn't work for templated functions if you have to supply the template parameters explicitly -- see this post: https://stackoverflow.com/a/2953783/27130