cpp:polymorphism

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cpp:polymorphism [2017/04/25 12:53]
gthanos [Pure Virtual συναρτήσεις και abstract κλάσεις]
cpp:polymorphism [2017/04/25 12:55]
gthanos
Line 5: Line 5:
 <code cpp ShapeUsage.cpp> <code cpp ShapeUsage.cpp>
 #include "Rectangle.cpp" #include "Rectangle.cpp"
-#include "Triangle.cpp" 
  
 int main() { int main() {
Line 115: Line 114:
  
 Επειδή η κλάση //Shape2D// είναι πλέον //abstract// δεν μπορεί να δώσει αντικείμενα. Έτσι η συνάρτηση //main// διαμορφώνεται ως εξής. Επειδή η κλάση //Shape2D// είναι πλέον //abstract// δεν μπορεί να δώσει αντικείμενα. Έτσι η συνάρτηση //main// διαμορφώνεται ως εξής.
 +<code cpp ShapeUsage.cpp>
 +#include "Rectangle.cpp"
  
 +int main() {
 +  Rectangle rectangle(0xffffff, 2, 10, 20);
 +  Shape2D &rect_ref = rectangle, *rect_ptr = &rectangle;
  
 +  cout << "Rectangle area: " << rectangle.getArea() << endl;
 +  cout << "Rectangle reference area: " << rect_ref.getArea() << endl;
 +  cout << "Rectangle pointer area: " << rect_ptr->getArea() << endl;
 +
 +</code>
  
  
cpp/polymorphism.txt · Last modified: 2020/04/15 08:48 (external edit)