C++_functions_classes_and_templates

C++_functions_classes_and_templates - C+ Functions,...

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

View Full Document Right Arrow Icon
CSE 332: C++ functions C++ Functions, Classes, and Templates C++ functions encapsulate behavior Data used/modified by a function must be passed in via parameters Data produced by a function must be passed out via return type Classes (and structs) encapsulate related data and behavior Member variables maintain each object’s state Member functions (methods) and operators have direct access to member variables Templates are used to make classes/structs/functions generic For example, vector class template can hold different data types For example, sort algorithm works with different containers as well
Background image of page 1

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

View Full DocumentRight Arrow Icon
CSE 332: C++ functions Declaring, Defining, Calling C++ Functions // function declarations in myfile.h void foo (); void baz (int j); // function definitions in myfile.cpp void baz (int j){ cout << j << endl; // prints passed value } void foo (){ int i = 7; // foo calls baz, passing variable i to it baz (i); }
Background image of page 2
CSE 332: C++ functions Declaring, Defining, Using C++ Structs/Classes
Background image of page 3

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

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

Page1 / 6

C++_functions_classes_and_templates - C+ Functions,...

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

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