SHARE
TWEET

Untitled

a guest Feb 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class A
  6. {
  7. private:
  8.     std::string value;
  9.  
  10. public:
  11.     A()
  12.     {
  13.         this->value = "A";
  14.     }
  15.  
  16.     virtual std::string ToString()
  17.     {
  18.         return this->value;
  19.     }
  20. };
  21.  
  22. class B : A
  23. {
  24. private:
  25.     std::string value;
  26.  
  27. public:
  28.     B() : A()
  29.     {
  30.         this->value = "B";
  31.     }
  32.  
  33.     std::string ToString()
  34.     {
  35.         return A::ToString() + " " + this->value;
  36.     }
  37. };
  38.  
  39. int main()
  40. {
  41.     A* a = new A();
  42.     B* b = new B();
  43.     std::cout << "Class A: " << a->ToString() << std::endl;
  44.     std::cout << "Class B: " << b->ToString() << std::endl;
  45.  
  46.     std::cin.get();
  47.     return 0;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top