title: Identifier is undefined
body: <p>I wrote the following code in C++ using VS2012 Express.  </p>
  
  <pre><code>void ac_search(
      uint num_patterns, uint pattern_length, const char *patterns, 
      uint num_records, uint record_length, const char *records,
      int *matches, Node* trie) {
  
    // Irrelevant code omitted.
  }    
  
  vector&lt;int&gt; ac_benchmark_search(
      uint num_patterns, uint pattern_length,
      const char *patterns, uint num_records, uint record_length,
      const char *records, double &amp;time) {
  
    // Prepare the container for the results
    vector&lt;int&gt; matches(num_records * num_patterns);
    Trie T;
    Node* trie = T.addWord(records, num_records, record_length);
  
    // error line
    ac_search(num_patterns, pattern_length, patterns, num_records,
              record_length, records, matches.data(), trie);    
  
    // Irrelevant code omitted.    
    return matches;
  }
  </code></pre>
  
  <p>I get the error <code>identifier "ac_search" is undefined</code> at the function invoking line. I am a bit confused here. because the function <code>ac_search</code> is declared as a global (not inside any container). Why can't I call it at this place? Am I missing something?  </p>
  
  <p><strong>Update</strong>  </p>
  
  <p>I tried ignore irrelevant code and then included it gradually and found that everything is fine until I include the outer loop of <code>ac_search</code> I get the aforementioned error. here is updated code of the function <code>ac_search</code>:  </p>
  
  <pre><code>void ac_cpu_string_search(uint num_patterns, uint pattern_length, const char *patterns, 
                         uint num_records, uint record_length, const char *records, int *matches, Node* trie)
  {
      // Loop over all records
      //for (uint record_number = 0; record_number &lt; num_records; ++record_number)
      //{
      //    // Loop over all patterns
          for (uint pattern_number = 0; pattern_number &lt; num_patterns; ++pattern_number)
          {
              // Execute string search
              const char *ptr_record = &amp;records[record_number * record_length];
              const char *ptr_match = std::strstr(ptr_record, &amp;patterns[pattern_number * pattern_length]);
  
              // If pattern was found, then calculate offset, otherwise result is -1
              if (ptr_match)
              {
                  matches[record_number * num_patterns + pattern_number] = static_cast&lt;int&gt;(std::distance(ptr_record, ptr_match));
              }
              else
              {
                  matches[record_number * num_patterns + pattern_number] = -1;
              }
      //    }
      //}
  }  
  </code></pre>
  
  <p><strong>Update 2</strong>    </p>
  
  <p>I think the error has something to do with the function <code>addWord</code> which belongs to the class <code>Trie</code>. When I commented out this function, I did not get the error anymore.</p>
  
  <pre><code>Node* Trie::addWord(const char *records, uint num_records, uint record_length)
  {
  
      // Loop over all records
      for (uint record_number = 0; record_number &lt; num_records; ++record_number)
      {
          const char *ptr_record = &amp;records[record_number * record_length];
          string s = ptr_record;
          Node* current = root;
          if ( s.length() == 0 )
          {
              current-&gt;setWordMarker(); // an empty word
              return;
          }
  
          for ( int i = 0; i &lt; s.length(); i++ )
          {        
              Node* child = current-&gt;findChild(s[i]);
              if ( child != NULL )
              {
                  current = child;
              }
                  else
                  {
                      Node* tmp = new Node();
                      tmp-&gt;setContent(s[i]);
                      current-&gt;appendChild(tmp);
                      current = tmp;
                  }
                  if ( i == s.length() - 1 )
                      current-&gt;setWordMarker();
          }
          return current;
      }  
  
  void ac_search(
          uint num_patterns, uint pattern_length, const char *patterns, 
          uint num_records, uint record_length, const char *records,
          int *matches, Node* trie) {
  
        // Irrelevant code omitted.
      }    
  
      vector&lt;int&gt; ac_benchmark_search(
          uint num_patterns, uint pattern_length,
          const char *patterns, uint num_records, uint record_length,
          const char *records, double &amp;time) {
  
        // Prepare the container for the results
        vector&lt;int&gt; matches(num_records * num_patterns);
        Trie T;
        Node* trie = T.addWord(records, num_records, record_length);
  
        // error line
        ac_search(num_patterns, pattern_length, patterns, num_records,
                  record_length, records, matches.data(), trie);    
  
        // Irrelevant code omitted.    
        return matches;
      }
  </code></pre>