Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. // ConsoleApplication7.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. class Parent {
  8.     friend class Priv_two;
  9. public:
  10.     int m_public;
  11. private:
  12.     int m_private;
  13. protected:
  14.     int m_protected;
  15. };
  16.  
  17. class Priv_one : private Parent {
  18. public:
  19.     int m_public;
  20.     int m_private;
  21.     int m_protected;
  22. };
  23.  
  24. class Priv_two : private Parent {
  25.     Parent pr;
  26. public:
  27.     void set_m_public(int value) {
  28.         pr.m_public = value;
  29.     }
  30.    
  31.     void set_m_private(int value) {
  32.         pr.m_private = value;
  33.     }
  34.  
  35.     void set_m_protected(int value) {
  36.         pr.m_protected = value;
  37.     }
  38.    
  39.     int get_m_public() {
  40.         return pr.m_public;
  41.     }
  42.  
  43.     int get_m_private() {
  44.         return pr.m_private;
  45.     }
  46.  
  47.     int get_m_protected() {
  48.         return pr.m_protected;
  49.     }
  50. };
  51.  
  52. int main()
  53. {
  54.     std::cout << "Var 1:" << std::endl;
  55.  
  56.     Priv_one priv_1;
  57.     priv_1.m_public = 0;
  58.     priv_1.m_private = 1;
  59.     priv_1.m_protected = 2;
  60.  
  61.     std::cout << "public: " << priv_1.m_public << std::endl
  62.         << "private: " << priv_1.m_private << std::endl
  63.         << "protected: " << priv_1.m_protected << std::endl;
  64.    
  65.     std::cout << std::endl;
  66.  
  67.     std::cout << "Var 2:" << std::endl;
  68.  
  69.     Priv_two priv_2;
  70.     priv_2.set_m_public(0);
  71.     priv_2.set_m_private(1);
  72.     priv_2.set_m_protected(2);
  73.  
  74.     std::cout << "public: " << priv_2.get_m_public() << std::endl
  75.         << "private: " << priv_2.get_m_private() << std::endl
  76.         << "protected: " << priv_2.get_m_protected() << std::endl;
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement