CS 330 Lecture 21 – Object-oriented Programming
March 24, 2014 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs330, lectures, spring 2014.
Agenda
- what ?s
- homework 3 – due before April 4
- textbook definition of OOP
- theorize this
- what does this do?
- Game of Life with Conditionals
TODO
Theorize This
On your own: How might polymorphism work?
With a neighbor: convince your neighbor that your theory is right.
What Does This Do?
class IntAndDouble {
public:
IntAndDouble() {}
private:
double d;
int i;
};
int main(int argc, char **argv) {
std::cout << sizeof(IntAndDouble) << std::endl;
return 0;
}
class TwoIntsAndDouble : public IntAndDouble {
public:
TwoIntsAndDouble() {}
private:
int j;
};
int main(int argc, char **argv) {
std::cout << sizeof(TwoIntsAndDouble) << std::endl;
return 0;
}
class IntAndDouble {
public:
IntAndDouble() {}
virtual int Get() const {
return i;
}
private:
double d;
int i;
};
class TwoIntsAndDouble : public IntAndDouble {
public:
TwoIntsAndDouble() {}
virtual int Get() const {
return j;
}
private:
int j;
};
int main(int argc, char **argv) {
std::cout << sizeof(IntAndDouble) << std::endl;
std::cout << sizeof(TwoIntsAndDouble) << std::endl;
return 0;
}
Polymorphism without Conditions
Code
Sizeof.cpp
#include <iostream>
class IntAndDouble {
public:
/* IntAndDouble() {} */
/* int Get() { return i; } */
private:
/* double d; */
int i;
int j;
};
int main(int argc, char **argv) {
std::cout << sizeof(IntAndDouble) << std::endl;
return 0;
}
Haiku
Dad said, “You can’t go”
I went and dug up his dad
“Gramps, make him say yes”