Tranvick

Example10

Jan 8th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. //Пример 10. Классы:
  2. //полиморфизм; виртуальные методы; абстрактные классы
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class A {
  9. public:
  10.     virtual void print() const = 0;
  11. };
  12.  
  13. class B : public A {
  14. public:
  15.     virtual void print() const {
  16.         cout << "Class B\n";
  17.     }
  18. };
  19.  
  20. class C : public B {
  21. public:
  22.     virtual void print() const {
  23.         cout << "Class C\n";
  24.     }
  25. };
  26.  
  27. int main() {
  28.     B * b, * c;
  29.     b = new B;
  30.     c = new C;
  31.     b -> print();
  32.     c -> print();
  33.     c -> B::print();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment