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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Key pointsClass explosion?• should supply destructor function so object candelete memory it allocated before it gets deleted itself• must supply copy constructor and operator=() ifmember-wise copy is not what we want• should return reference in case where object could beon left hand side of assignmentSuppose we want SimpleIntArray?Could copy SimpleFloatArray, edit everywherewe find float and save to create new class• tedious work• duplicate code• we’ll want to <strong>the</strong> same for double, Hep3VectorF,etc.Could use void * instead of float and <strong>the</strong>n castreturn values.• only C programmers know what I’m talking about• bad idea because we lose type safetyIf we have n data types and m things to work with<strong>the</strong>m, we don’t want to have to write n x m classesEnter template feature of <strong>C++</strong> to solve this problem<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 111 Paul F. Kunz<strong>BABAR</strong> <strong>C++</strong> <strong>Course</strong> 112 Paul F. Kunz

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

Saved successfully!

Ooh no, something went wrong!