Class Notes (835,638)
United States (324,200)
CS 24000 (56)
Lecture 21

CS 24000 Lecture 21: Paramters, types and templates introduction 03302017
Premium

3 Pages
43 Views
Unlock Document

Department
Computer Sciences
Course
CS 24000
Professor
Adams George
Semester
Winter

Description
CS 240 lecture 21 03302017-Paramters, types and templates introduction Default parameters • You can set default parameters • The default parameters should be the last one in a function declaration • Example: void drawRect(int x, int y, int width=100, int height=100); drawRect(45, 67); // Use defaults.
drawRect(78, 96, 45); // Use default height only. • Only the declaration includes the default parameters and not the implementation Overloading functions • Also in C++ you can have multiple functions with the same name as long as the types of the arguments re different • When calling a function C++ will use the function that best matches the types Overloading functions print(int a) { ...} print(const char * s) {... } print(double d) {...} ...
 int x = 9;
 double y = 89.78;
 const char * z = “Hello world”; print(x); // Uses print(int a);
 print(y); // Uses print(double d) print(z); // Uses print(const char * s) Operator overloading • You can also define your own operators in C++ • For example, if you have a class class A { ... } • then you can define an operator A operator + (const A &s1, const A &s2) { ... } • and use it as: Aa; Ab;
// Initialize a and b A c = a + b;
 Classes • remember that classes in C++ use two files • .h (or .hh) has the class declaration with the name of the methods and variables • .cpp (or .cc or .cxx) has the implementation Private:/protected:/public: • Variables inside a class can be defined private, protected or public • Private: o It means that every method or variable after a private: declaration can be used only by the class that defines it • Protected: o It means that every method or variable after a protected: declaration can be used only by the class or subclass that defines it • Public: o It means that every method or variable after public declaration can be used by anybod
More Less

Related notes for CS 24000

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit