title: C++: Why does my DerivedClass's constructor not have access to the BaseClass's protected field?
body: <p>I have a constructor attempting to initialize a field in a base class. The compiler complains. The field is protected, so derived classes should have access.</p>
  
  <pre><code>//The base class: 
  
  class BaseClass
  
  {
  
  public:
  
      BaseClass(std::string);
      BaseClass(const BaseClass&amp; orig);
      virtual ~BaseClass();
      const std::string GetData() const;
      void SetData(const std::string&amp; data);
  protected:
  
      BaseClass();
      std::string m_data;
  
  };
  
  BaseClass::BaseClass(const std::string data) : m_data(data) { }
  
  BaseClass::BaseClass() { } 
  
  BaseClass::BaseClass(const BaseClass&amp; orig) { }
  
  BaseClass::~BaseClass() { }
  
  void BaseClass::SetData(const std::string&amp; data)
  {
      m_data = data;
  }
  
  const std::string BaseClass::GetData() const
  {
      return m_data;
  }
  
  
  //The derived class: 
  
  
  class DerivedClass : public BaseClass
  {
  
  public:
  
      DerivedClass(std::string data);
      DerivedClass(const DerivedClass&amp; orig);
      virtual ~DerivedClass();
  private:
  
  };
  
  DerivedClass::DerivedClass(std::string data) : m_data(data) { } //ERROR HERE
  
  DerivedClass::DerivedClass(const DerivedClass&amp; orig) { }
  
  DerivedClass::~DerivedClass() { }
  </code></pre>
  
  <p>//The compiler error</p>
  
  <p>DerivedClass.cpp:3: error: class ‘DerivedClass’ does not have any field named ‘m_data’</p>
  
  <p>Any help is greatly appreciated. Thank you in advance.</p>