CMSC 202 Computer Science II, Spring 2007, Section 010x
Lecture 3: C++ Primer
Tuesday 02/06, 2007
Assigned Reading: 11
Slides As Shown:
- TA Office Hours Posted
- CMSC 202 Mailing List
- Computer Science Help Center Open
- Project 1 will be posted by noon next Monday
- You're reading the textbook, right?
- Recapped some differences between C and C++ from last time.
- Discussed C++ References.
(Slides posted last week.)
- Note: Don't try to make sense of the & notation.
- Simple test of references: ref1.cpp, ref1.txt
- References used for parameter passing:Parameter Passing by Reference.
Note no dereferencing in swap() function. Also, no address-of in function call.
Important: C programmer would not think calling swap() would change the values of a and b.
- Const reference parameters cannot be modified by the function called
but also are not copied.
- Discussed function overloading. See slides.
Some example programs.
Simple resolution with type:
Simple resolution with number:
Example of promotion and downcasting:
Tricky resolution (don't do this!):
Do it this way, using typecasting:
Promoting int to double&:
Const& and ref:
Can't resolve pass by value vs pass by const ref:
- Discussed scope, lifetime and namespaces. See slides.
[Spring '07 CMSC202]
6 Feb 2007 16:12:07 EST