07.03.2013 Views

here - Chara - University of Illinois at Urbana-Champaign

here - Chara - University of Illinois at Urbana-Champaign

here - Chara - University of Illinois at Urbana-Champaign

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Lecture<br />

04—Templ<strong>at</strong>e<br />

P<strong>at</strong>terns I<br />

Chase Geigle<br />

Announcements<br />

Templ<strong>at</strong>e<br />

Specializ<strong>at</strong>ion<br />

Partial<br />

Templ<strong>at</strong>e<br />

Specializ<strong>at</strong>ion<br />

Templ<strong>at</strong>e<br />

Templ<strong>at</strong>e<br />

Parameters<br />

Next Time<br />

Original Implement<strong>at</strong>ion<br />

#include <br />

templ<strong>at</strong>e <br />

class vector {<br />

public:<br />

// purposefully not doing reference <strong>here</strong>...<br />

T oper<strong>at</strong>or[]( size_t i ) {<br />

return d<strong>at</strong>a_[ i ];<br />

}<br />

// other things<br />

priv<strong>at</strong>e:<br />

T * d<strong>at</strong>a_;<br />

};<br />

If T = bool, we are wasting an entire byte on th<strong>at</strong><br />

boolean value (which can, in theory, be represented as a<br />

single bit)

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

Saved successfully!

Ooh no, something went wrong!