I am working on a hw assignment, and am following a template given by my prof. However, I keep getting an 'argument not declared in scope' error, even though his works perfectly. Here's the code:
#include <cstring>
#include <iostream>
namespace cop3530{
int linear_probe(int i, std::size_t cap){
return (i % cap);
}
int quadratic_probe(int i, std::size_t cap){
return((i*i) % cap);
}
int double_hash(int i, std::size_t cap){
unsigned int b = 2689;
unsigned int a = 3359;
unsigned int hash2 = 0;
for(std::size_t i = 0; i < cap; i++)
{
hash2 = hash2 * a + i;
a = a * b;
}
return hash2;
}
template<typename T, typename FUNC, FUNC func>
class hash_table{
//...
//here's an example of where the func would be used
bool insert(T k, char v){
std::size_t cap = this->capacity();
//check to see if table is full
if(cap == this->size()){
std::cout<< "The table is full, and items can not be inserted"<< std::endl;
return false;
}
else{
int i = hash(k, cap);
int probe = func(i, cap);
while(key[i] != NULL){
i = i+ probe;
if( i >= cap)
i = i - cap;
}
if (!search(k,v))
key[i] = k;
value[i] = v;
return true;
}
}; //end classs
}//end namespace
int main(){
cop3530::hash_table<int, int, linear_probe> ht(10); //here is where error occurs, says
//linear_probe is not declared within scope
}//end main
Obviously this is not the full code, but I included the parts that I thought were important for the error (I don't even think you need to see my insert function, but I put it there just in case). Thank you!