Kroll

one1

Nov 12th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4. using std::string;
  5.  
  6. class Ancestor
  7. {
  8.   public:
  9.   Ancestor(): var("ancestor")
  10.   {
  11.   }
  12.  
  13.   protected:
  14.   string var;
  15. };
  16.  
  17. class Child1 : public Ancestor
  18. {
  19.   public:
  20.   Child1()
  21.   {
  22.     this->var="child1";
  23.   }
  24. };
  25. class Child2 : public Ancestor
  26. {
  27.   public:
  28.   void output(Ancestor &subject)
  29.   {
  30.     cout << subject.var << endl;
  31.   }
  32. };
  33.  
  34. int main()
  35. {
  36.   Child1 child1;
  37.   Child2 child2;
  38.  
  39.   child2.output(child1);
  40.  
  41. return 0;
  42. }
  43.  
  44. //$ g++ one1.cpp
  45. //one1.cpp: В функции-члене ‘void Child2::output(Ancestor&)’:
  46. //one1.cpp:14:10: ошибка: ‘std::string Ancestor::var’ is protected
Advertisement
Add Comment
Please, Sign In to add comment