title: Trouble referencing data member from member function
body: <p>Line 23 is:</p>
  
  <pre><code>List[i] = x;
  </code></pre>
  
  <p>When I try to compile:</p>
  
  <pre><code>g++ w3.cpp list.cpp line.cpp
  list.cpp: In member function void List::set(int):
  list.cpp:23:8: error: expected unqualified-id before [ token
  </code></pre>
  
  <p>Here's main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  #include "list.h"
  
  int main() {
      int no;
      List list;
  
      cout &lt;&lt; "List Processor\n==============" &lt;&lt; endl;
      cout &lt;&lt; "Enter number of items : ";
      cin  &gt;&gt; no;
  
      list.set(no);
      list.display();
  }
  </code></pre>
  
  <p>Here's list.h:</p>
  
  <pre><code>#include "line.h"
  #define MAX_LINES 10
  using namespace std;
  
  struct List{
      private:
          struct Line line[MAX_LINES];
      public:
          void set(int no);
          void display() const;
  };
  </code></pre>
  
  <p>Here's line.h:</p>
  
  <pre><code>#define MAX_CHARS 10
  struct Line {
      private:
          int num;
          char numOfItem[MAX_CHARS + 1]; // the one is null byte
      public:
          bool set(int n, const char* str);
          void display() const;
  };
  </code></pre>
  
  <p>Here's list.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  #include "list.h"
  //#include "line.h" - commented this line because it was giving me a struct redefinition error
  
  void List::set(int no) {
  
      int line;
      char input[20];
  
      if (no &gt; MAX_LINES)
          no = MAX_LINES;
  
      for (int i = 0; i &lt; no; i++) {
      Line x;
          cout &lt;&lt; "Enter line number : ";
          cin &gt;&gt; line;
          cout &lt;&lt; "Enter line string : ";
          cin &gt;&gt; input;
  
          if (x.set(line, input)){
              List[i] = x;
              cout &lt;&lt; "Accepted" &lt;&lt; endl;
          }
          else
              cout &lt;&lt; "Rejected" &lt;&lt; endl;
  
      }
  }
  
  void List::display() const {
  
  
  
  }
  </code></pre>