title: C++: why base object is not accessible inside derived class if protected
body: <p>Am a newbie to C++.</p>
  
  <pre><code>class A 
  {
      public:
          int i;
      protected: //**--- [1]**
          void set()
          {
              i=5;
              cout&lt;&lt;i;
          }
  };
  
  class B : public A
  {
      public:
          void call()
          {
              A obj;
              obj.set(); //**----[2]**
              set(); //**---[3]**
          }
  };
  
  int main()
  {
      B* b_obj = new B;
      b_obj-&gt;call();
  }
  </code></pre>
  
  <p>Why doesn't the code compiled if i try including <strong>[2]</strong> and not replacing <strong>[1]</strong> to public BUT it works if i compile including <strong>[3]</strong> alone?</p>
  
  <p>Compiled error: error: ‘void A::set()’ is protected.</p>
  
  <p>In short, My intention is to understand why base object cannot be called in derived class if the access specifier for the base class interface is set as protected.   </p>