Classes and objects I
Lecture 13
Table of Contents
Review
Questions about the last class?
Quiz
Is C object-oriented?
Quiz Discussion
Adding Objects to SimpleC
- C++-style objects
- Class type declaration
- Separate implementation of methods
Objects
- Bundle fields and methods
- Encapsulates data (scoping and namespacing)
- Hides implementation details
- Define abstract data types
Hash table vs. Dictionary
Linked-list vs. Vector
Hand-wiring an appliance to the electrical grid vs. using an electrical outlet
Objects in C
Bundling fields together
How can we do this in C?
structs bundle fields
struct point { int x; int y; };
Bundling fields and methods?
How can we do this in C?
We can store function pointers
struct point { int x; int y; int (* addX) (int); // function pointer };