13.07.2015 Views

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

BABAR C++ Course Running the Examples - HEPHY

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Operator Function ImplementationCompare Fortran and <strong>C++</strong>Implementationinline Hep3VectorF& Hep3VectorF::operator+=(const Hep3VectorF& p) {fx += p.x();fy += p.y();fz += p.z();return *this;}• does <strong>the</strong> accumulation as one would expect• this is a keyword representing a pointer to <strong>the</strong>object’s own selfFortran vector sum<strong>C++</strong> vector sumreal p(3), q(3)! ...q(1) = q(1) + p(1)q(2) = q(2) + p(2)q(3) = q(3) + p(3)Hep3VectorF p, q;// ...q += p;• this->fx is thus equivalent to fx• remember: use -> instead of . when you have apointer• or fx is shorthand for this->fx• recall that Hep3VectorF::x() is an in-linefunction itself• return *this returns <strong>the</strong> address of <strong>the</strong> object,thus <strong>the</strong> reference<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 88 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 89 Paul F. Kunz

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!