My question is about passing objects to functions by reference. It seems like a function such as save() in my simple example below should be passed an object by reference to avoid the overhead of copying the object, and it should also be passed using const as we don't want or need save() to modify the object. This works fine when the variable x is public, but in the example below where x is private and accessor functions are used, it doesn't.
So, my question is how do you pass objects using const when the class has accessor functions? I tried making save() a friend of MyClass, which worked as save() can now directly access x, but even when save() is a friend it cannot use get_x() to access x. Is there another way to do this so that save() can access x via get_x()?