[cpp] operator

Viewer

copydownloadembedprintName: operator
  1. struct Vec3
  2. {
  3.         float x, y, z;
  4.         //negative operator
  5.         Vec3 operator -() const { return Vec3{-x, -y, -z}; }
  6.         //subtract operator
  7.         Vec3 operator - (const Vec3 & r) const { return Vec3{- r.x, y - r.y, z - r.z}; }
  8. };

Editor

You can edit this paste and save as new: