Week 10 Class 18 Thu Mar 16 Posted: Mar 16
After Class
[&]
.Project 3 Pass std::string_view
as an IN parameter by value, not const reference:
Use | Don't Use |
---|---|
std::string_view
consists of a pointer (to the actual memory) and a size, and is equivalent to the following:
Since this is so small, passing by value is efficient. While it takes the same number of assembly operations, it requires an extra pointer dereference, and timings show they are equivalent.
Announcements
Midterm
Midterm scores and feedback are posted in Brightspace:
@stereotype get
method for total bytes.Class
Exercise 49: Base
virtual
methods in C++ support dynamic polymorphism. Dynamic polymorphism only occurs with pointers and references to objects, passing by value is not polymorphic.
The classes in this exercise are Base, Derived which inherits from Base, and DerivedDerived which inherits from Derived. So Derived is a Base, and DerivedDerived is a Derived and therefore also is a Base.
The method m1()
is not virtual, so it does not provide for polymorphism.
The method m2()
is virtual, so it does provide for polymorphism.
Complete the assertions in the code that indicate (via a string) which method is called, e.g., for m1()
is it "Base::m1()"
,
"Derived::m1()"
, or "DerivedDerived::m1()"
?
Complete each assertion one at a time in order, compiling and running the program (i.e., make run
) after each assertion is completed. The assertion you edited should pass, and you should be onto the next assertion.
You are required to commit for each block of statements in the main program.
The GitHub Classroom link is in Brightspace.
All exercises are due by 4:30 pm on Monday, Mar 27