I would like to know if there’s a “widely accepted” naming convention in C++ when writing such methods:
class Transform3d {
public:
// Apply rotation using a copy of toRotate and return it
Vector3d ApplyRotation(const Vector3d& toRotate) const;
// Apply rotation directly to toRotate
void ApplyRotationInPlace(Vector3d& toRotate) const;
// Apply rotation on this Transform3d instance (orientation quat)
void ApplyRotation(const Vector3d& toRotate);
//...
// Apply transformation using a copy of toTransform and return it
Transform3d ApplyTransform(const Vector3d& toTransform) const;
// Apply transformation directly to toTransform
void ApplyTransformInPlace(Vector3d& toTransform) const;
private:
Quaternion orientation;
Vector3d position;
};
Is there some guidelines for writing C++ method which deals with parameters modification and return new instance (with no modification on the parameter) ?
Yes, and you stumbled upon it. It’s the
constmodifiers.By marking your parameters
const, that’s exactly what you guarantee.constis really there for the developers.