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!

>>I keep getting an 'argument not declared in scope' error, even though his works perfectly

Talk about a contridction of terms! You get compile errors but yet you claim it works perfectly :icon_eek:

Solve the problem in one of two ways: cop3530::hash_table<int, int, cop3530::linear_probe> ht(10); or adding this at near the top of the *.cpp file using namespace cop3530;

Use cop3530::linear_probe

>>I keep getting an 'argument not declared in scope' error, even though his works perfectly

Talk about a contridction of terms! You get compile errors but yet you claim it works perfectly :icon_eek:

Solve the problem in one of two ways: cop3530::hash_table<int, int, cop3530::linear_probe> ht(10); or adding this at near the top of the *.cpp file using namespace cop3530;

I meant that my teacher's works perfectly, and I was following his format completely. I will try this.

ok, so i put in
cop3530::hash_table<int, int, cop3530::linear_probe> ht(10);

but now im getting that it can not convert cop3530::linear_probe to an 'int', which doesnt make sense to me since linear_probe is of type int.

Try this :

cop3530::hash_table<int,cop3530::linear_probe> ht(10);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.