{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C++_functions_classes_and_templates

C++_functions_classes_and_templates - C Functions Classes...

Info icon This 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
Image of page 1

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

View Full Document Right 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); }
Image of page 2
CSE 332: C++ functions Declaring, Defining, Using C++ Structs/Classes // struct declaration in point2d.h struct Point2D {
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern