Cpp_notes_summary_6

Cpp_notes_summary_6 - MAT 5939-04 Pierre Garreau 5.3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MAT 5939-04 Pierre Garreau 5.3 Classes: a second approach This section is motivated by a need for clarification of C++ codes and elementary operations. It is taken from Scott Meyers book, Effective C++ second edition . 5.3.1 C++ elementary operations Definition vs Declaration There is a fundamental difference between declarations and definition . The declaration often precedes the definition by telling the compiler the type of an object, for instance: Declaration double MidPointRule ( double , double , int , double ( f )( double ) ) ; class Timer ; ostream& operator << ( ostream& output , const Matrix& mat) A definition specifies the details of the object, for instance when writting a class or a function. Definition double MidPointRule ( double a , double b , int N, double ( f )( double )) { double in te gr al valu e = 0; double delta = (b a)/N; double x = 0; for ( int i = 0; i < N; i++) { x = a + ( i +0.5) delta ; in te gr al valu e += f (x) delta ; } in te gr al valu e /= 2 . 0 ; } ; class Timer { public : Timer ( ) ; virtual Timer ( ) ; public : void start timer ( ) ; void stop timer ( ) ; double Get time elapsed ( ) ; private : double start , stop ; } ; Declarations are the purpose of header files (.h), whereas definitions are done in source files (.cpp)....
View Full Document

This note was uploaded on 01/15/2012 for the course MAT 5939 taught by Professor Garreau during the Fall '11 term at FSU.

Page1 / 4

Cpp_notes_summary_6 - MAT 5939-04 Pierre Garreau 5.3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online