Tags: lec7

Q: What is the difference between a struct and class in C++?
A: They are basically the same, except that members are public by default in structs and private by default in classes.

Q: How do you make members of a struct/class public/private?
A: Within the class/struct definition, put:
public:
OR
private:
...before the declarations with that visibility.  A single "public:" or "private:" may be used prior to many declarations.

Q: class C {
    void MyMethod(); // declaration
}
// how should MyMethod be defined down here?
A: void C::MyMethod {
    ...
}

Q: What is "this" in C++?
A: a pointer to the object on which the current method was invoked

Q: If you want to add custom support for printing an object with cout (or similar), what must you do?
A: overload this:
operator<<

Q: When is a destructor called on an object?
A: Just before the memory for that object is released (e.g., when a function returns or delete is called).

Q: What is a difference between the two following styles (besides the difference in syntax)?
// style 1
House::House(int beds, float sq_ft, int x, int y) {
  this->beds = beds;
  sq_m = sq_ft / 10.76;
  coord = {.x=x, .y=y};
}
// style 2
House::House(int beds, float sq_ft, int x, int y):
  beds{beds},
  sq_m{sq_ft/10.76f},
  coord{x,y}
{}
A: In this first one, an object for coord will be created twice -- before the constructor runs, and for this line: "coord = {.x=x, .y=y};".  The second object replaces the first.
In the second style, an object for coord is only created once.