title: Accessing methods of an object from another object (Suggest for a better approach?)
body: <p>I would like to preserve encapsulation and abstraction but I am really having trouble about editing this. I did this program in C and it worked but converting it to an OOP is really a headache for me. This program is an .ini file reader which has this format:</p>
  
  <p><code>[sections]
  keys = values</code></p>
  
  <pre><code>XKey::XKey(const char *k, const char *v)
  {
      free(m_name);
      free(m_value);
      m_name = strdup(k);
      m_value = strdup(v);
      m_next = 0;
  }
  
  XKey *XSection::addKey(const char *k, const char *v)
  {
      XKey *kn = new XKey(k, v);
      XKey *ks;
  
      if (m_keys == 0) {
          m_keys = kn;
          return kn;
      }
  
      ks = m_keys;
  
      while (ks-&gt;m_next)
          ks = ks-&gt;m_next;
  
      ks-&gt;m_next = kn;
      return kn;
  }
  
  XKey::~XKey()
  {
  
  }
  
  XSection::XSection(const char *s)
  {
     free(m_name);
     m_name = strdup(s);
     m_next = 0;
     m_keys = 0;
  }
  
  XSection *XIniFile::addSection(const char *d)
  {
      XSection *sn = new XSection(d);
      XSection *ss;
  
      if (m_sections == 0) {
          m_sections = sn;
          return sn;
      }
  
      ss = m_sections;
  
      while(ss-&gt;m_next)
          ss = ss-&gt;m_next;
  
      ss-&gt;m_next = sn;
      return sn;
  }
  
  XSection::~XSection()
  {
  
  }
  
  XIniFile::XIniFile()
  {
      m_sections = 0;
      m_modified = FALSE;
  }
  
  int XIniFile::open(const char *fn)
  {   
      //do some routines here to get string values for 
      //sn               &lt;--section name
      //kn               &lt;--key name
      //val               &lt;--value name
      //do loop here to insert all the sections   
              cs = addSection(sn);
              //do loop here to add all the keys and values on every section 
              //then move to the next section    
                  addKey(kn, val);    
  
      return 0;
  }
  
  XIniFile::~XIniFile()
  {
  }
  </code></pre>
  
  <p>Here is a snippet of my .h file</p>
  
  <pre><code>class XKey
  {
      friend class XSection;
      friend class XIniFile;
  
  public:
      XKey(const char *, const char *);
      virtual ~XKey();
  
  private:
      char *m_name;
      char *m_value;
      XKey *m_next;
  };
  
  class XSection
  {
      friend class XIniFile;
  
  public:
      XSection(const char *);
      XKey *addKey(const char *, const char *);
      virtual ~XSection();   
  
  private:    
      char *m_name;
      XKey *m_keys;
      XSection *m_next;
  };
  
  class XIniFile
  {
  private:
      char *m_name;
      XSection *m_sections;
      int m_modified;
  
      XSection *addSection(const char *);
  
  public:
      XIniFile();
      virtual ~XIniFile();
  };
  </code></pre>
  
  <p>I hope you could understand the program that I am doing. Basically I am just storing them in a linked list.</p>
  
  <p>I am having problems with this error <code>addKey was not declared in this scope</code> so I guess my approach is not really good.</p>