Miscellaneous
1 class hours
Scope and Parameter Passing
Design by Contract
Enums
Stack and Heap memory
Motivating example
struct point {
double x;
double y;
};
cp::string to_string(point* p) {
return cp::to_string('(') + cp::to_string(p->x) + ", "
+ cp::to_string(p->y) + ")";
}
point* foo(double x_coord, double y_coord) {
point p = {x_coord, y_coord};
return &p;
}
point* foo_h(double _x, double _y) {
point* p = new point({_x, _y});
return p;
}
void bar() {
point* q = foo_h(2, 3);
cp::println(to_string(q));
}
int main() {
bar();
return 0;
}