Identifier is undefined
Posted
by
hawk
on Stack Overflow
See other posts from Stack Overflow
or by hawk
Published on 2013-10-19T12:28:10Z
Indexed on
2013/10/21
9:54 UTC
Read the original article
Hit count: 269
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;
}
© Stack Overflow or respective owner