This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog:fall2021:projects:oop2 [2021/11/09 21:41] – [Polymorphism] pleblanc | notes:cprog:fall2021:projects:oop2 [2021/11/11 04:58] (current) – [References] hhemler | ||
---|---|---|---|
Line 19: | Line 19: | ||
====Polymorphism==== | ====Polymorphism==== | ||
+ | |||
+ | Polymorphism, | ||
===Compile Time Polymorphism=== | ===Compile Time Polymorphism=== | ||
Compile time polymorphism is achieved by overloading. This can be in the form of operator overloading, | Compile time polymorphism is achieved by overloading. This can be in the form of operator overloading, | ||
+ | |||
+ | Overloading is takes place when more than one function or operator, with the same name and scope, are given differing definitions. | ||
+ | |||
+ | It is called compile-time polymorphism because a function is called at the time of program compilation. | ||
==Template Functions== | ==Template Functions== | ||
Line 66: | Line 72: | ||
===Run Time Polymorphism=== | ===Run Time Polymorphism=== | ||
Run time polymorphism is achieved by overriding. Overriding occurs when a child class redefines a parent class' | Run time polymorphism is achieved by overriding. Overriding occurs when a child class redefines a parent class' | ||
+ | |||
+ | In a runtime polymorphism, | ||
==Virtual Functions== | ==Virtual Functions== | ||
Line 116: | Line 124: | ||
//Notice objects deriving from Rectangle are passed by reference because if you pass by value a new Rectangle object will be created, therefore using Rectangle methods.// | //Notice objects deriving from Rectangle are passed by reference because if you pass by value a new Rectangle object will be created, therefore using Rectangle methods.// | ||
====Access Control implications==== | ====Access Control implications==== | ||
+ | |||
+ | Access control is important in polymorphism as it restricts or allows access to class members. | ||
+ | |||
+ | |||
====Parent-Child Relationships==== | ====Parent-Child Relationships==== | ||
+ | Parent child relationships refer to base classes and the derived classes that inherit from them. In regards to polymorphism, | ||
+ | |||
+ | Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. | ||
+ | ====Similarities to word origins==== | ||
+ | It is strange that what is called ' | ||
+ | |||
+ | COOL BUG FACT: After writing this I found that " | ||
+ | |||
+ | RELEVANT COOL BUG FACT: If the child class has a child of its own, the polymorphed version of functions will be what the child' | ||
=====Program===== | =====Program===== | ||
Write a program that makes use of polymorphism. It can be anything, so long as you genuinely implement it and it works. | Write a program that makes use of polymorphism. It can be anything, so long as you genuinely implement it and it works. | ||
Line 127: | Line 148: | ||
=====References===== | =====References===== | ||
- | https:// | + | * https:// |
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
=====Submission===== | =====Submission===== | ||
I'll be looking for the following: | I'll be looking for the following: |