Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. /////////// PLIK .h /////////////////////////////
  2. #pragma once
  3.  
  4. #include <string>
  5.  
  6. class A {
  7. public:
  8.     virtual std::string getName() = 0;
  9.     friend std::string getNameFriend();
  10. };
  11.  
  12. class B : public A {
  13. public:
  14.     virtual ~B();
  15.     virtual std::string getName();
  16. };
  17.  
  18. class C : public B {
  19. public:
  20.     virtual ~C();
  21.     virtual std::string getName();
  22. };
  23.  
  24. ///////////////// PLIK .cpp ////////////////////////////////////
  25.  
  26. #include "stdafx.h"
  27. #include "Paradygmaty1.h"
  28.  
  29. B::~B()
  30. {
  31. }
  32.  
  33. std::string B::getName()
  34. {
  35.     return "B";
  36. }
  37.  
  38. C::~C()
  39. {
  40. }
  41.  
  42. std::string C::getName()
  43. {
  44.     return "C";
  45. }
  46.  
  47. std::string getNameFriend()
  48. {
  49.     return "A";
  50. }
  51.  
  52. ///////////////// Main.cpp ///////////////////////////////////////////
  53.  
  54. #include "stdafx.h"
  55. #include <iostream>
  56. #include <conio.h>
  57. #include "Paradygmaty1.h"
  58.  
  59.  
  60. int main()
  61. {
  62.     A *a = new B();
  63.     A *a2 = new C();
  64.     std::cout << getNameFriend() << " -> " << a->getName() << " -> " << a2->getName();
  65.  
  66.     delete a;
  67.     delete a2;
  68.  
  69.     _getch();
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement