[c++] Identifier is undefined

I wrote the following code in C++ using VS2012 Express.

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<int> ac_benchmark_search(
    uint num_patterns, uint pattern_length,
    const char *patterns, uint num_records, uint record_length,
    const char *records, double &time) {

  // Prepare the container for the results
  vector<int> 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;
}

I get the error identifier "ac_search" is undefined at the function invoking line. I am a bit confused here. because the function ac_search is declared as a global (not inside any container). Why can't I call it at this place? Am I missing something?

Update

I tried ignore irrelevant code and then included it gradually and found that everything is fine until I include the outer loop of ac_search I get the aforementioned error. here is updated code of the function ac_search:

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 < num_records; ++record_number)
    //{
    //    // Loop over all patterns
        for (uint pattern_number = 0; pattern_number < num_patterns; ++pattern_number)
        {
            // Execute string search
            const char *ptr_record = &records[record_number * record_length];
            const char *ptr_match = std::strstr(ptr_record, &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<int>(std::distance(ptr_record, ptr_match));
            }
            else
            {
                matches[record_number * num_patterns + pattern_number] = -1;
            }
    //    }
    //}
}  

Update 2

I think the error has something to do with the function addWord which belongs to the class Trie. When I commented out this function, I did not get the error anymore.

Node* Trie::addWord(const char *records, uint num_records, uint record_length)
{

    // Loop over all records
    for (uint record_number = 0; record_number < num_records; ++record_number)
    {
        const char *ptr_record = &records[record_number * record_length];
        string s = ptr_record;
        Node* current = root;
        if ( s.length() == 0 )
        {
            current->setWordMarker(); // an empty word
            return;
        }

        for ( int i = 0; i < s.length(); i++ )
        {        
            Node* child = current->findChild(s[i]);
            if ( child != NULL )
            {
                current = child;
            }
                else
                {
                    Node* tmp = new Node();
                    tmp->setContent(s[i]);
                    current->appendChild(tmp);
                    current = tmp;
                }
                if ( i == s.length() - 1 )
                    current->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<int> ac_benchmark_search(
        uint num_patterns, uint pattern_length,
        const char *patterns, uint num_records, uint record_length,
        const char *records, double &time) {

      // Prepare the container for the results
      vector<int> 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;
    }

This question is related to c++ visual-c++ visual-studio-2012

The answer is


You may also be missing using namespace std;


Are you missing a function declaration?

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);

Add it just before your implementation of ac_benchmark_search.


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to visual-c++

How to install Visual C++ Build tools? Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat) How to install numpy on windows using pip install? How to use _CRT_SECURE_NO_WARNINGS How to play or open *.mp3 or *.wav sound file in c++ program? What is C# equivalent of <map> in C++? The program can't start because MSVCR110.dll is missing from your computer error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj Identifier is undefined error LNK2001: unresolved external symbol (C++)

Examples related to visual-studio-2012

How to actually search all files in Visual Studio Tests not running in Test Explorer How to use _CRT_SECURE_NO_WARNINGS Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0 How can I resolve the error: "The command [...] exited with code 1"? Could not load file or assembly Exception from HRESULT: 0x80131040 MSVCP120d.dll missing How can I change IIS Express port for a site The program can't start because MSVCR110.dll is missing from your computer Controlling execution order of unit tests in Visual Studio