[Solved]Keep Getting Ambiguous Overload Error Program Someone Please Help Fix File Implement Table Q37244377
I keep getting an ambiguous overload error for my program, cansomeone please help me fix it? The file I had to implement wastable2.template but I’ve provided the header and test file as well.They are the only files used to make the template and no changesare allowed to be made to them. Thanks!
Here’s all the programs:
table2.h
// FILE: table2.h
// TEMPLATE CLASS PROVIDED: Table
// This class is a container template class for a Table ofrecords.
// The template parameter, RecordType, is the data type of therecords in the
// Table. It may any type with a default constructor, a copyconstructor,
// an assignment operator, and an integer member variable calledkey.
//
// CONSTRUCTOR for the Table template class:
// Table( )
// Postcondition: The Table has been initialized as an emptyTable.
//
// MODIFICATION MEMBER FUNCTIONS for the Table class:
// void insert(const RecordType& entry)
// Precondition: entry.key >= 0
// Postcondition: If the table already had a record with a keyequal to
// entry.key, then that record is replaced by entry. Otherwise,entry has
// been added as a new record of the Table.
//
// void remove(int key)
// Postcondition: If a record was in the Table with the specifiedkey, then
// that record has been removed; otherwise the table isunchanged.
//
// CONSTANT MEMBER FUNCTIONS for the Table class:
// bool is_present(const Item& target) const
// Postcondition: The return value is true if there is a record inthe
// Table with the specified key. Otherwise, the return value isfalse.
//
// void find_location(int key, bool& found,
// typename std::list::iterator& location) const
// Postcondition: If a record is in the Table with the specifiedkey, then
// found is true and location is set to an iterator access therecord.
// Otherwise found is false and the result contains garbage.
//
// size_t size( ) const
// Postcondition: Return the total number of records in the
// Table.
//
#ifndef TABLE2_H
#define TABLE2_H
#include // Provides size_t
#include
#include
namespace main_savitch_12B
{
template
class table
{
public:
// MEMBER CONSTANT
static const std::size_t NUM_BUCKETS = 10;
// CONSTRUCTORS AND DESTRUCTOR
table( );
// MODIFICATION MEMBER FUNCTIONS
void insert(const RecordType& entry);
void remove(int key);
// CONSTANT MEMBER FUNCTIONS
bool is_present(int key) const;
RecordType get_record (int key) const;
std::size_t size( ) const;
template
friend std::ostream& operator << (std::ostream&output,
const table& t);
private:
std::list data[NUM_BUCKETS];
// HELPER MEMBER FUNCTION
std::size_t hash(int key) const;
void find_location(int key, bool& found,
typenamestd::list::iterator&
location);
};
}
#include “table2.template” // Include the implementation
#endif
=======================================================================
table2.template
//File. table2.template
//This program implements the functions of the header file
#include
#include
#include
#include “table2.h”
using namespace std;
using namespace main_savitch_12B;
//Postcondition: The Table has been initialized as an emptyTable.
template
table::table( ) {
}
//Precondition: entry.key >= 0
//Postcondition: If the table already had a record with a key equalto
//entry.key, then that record is replaced by entry. Otherwise,entry has
//been added as a new record of the Table.
template
void table::insert(const RecordType& entry) {
assert(entry.key >= 0);
size_t index = hash(entry.key);
if(!is_present(entry.key)) {
data[index].push_back(entry);
} else {
remove(entry.key);
data[index].push_back(entry);
}
}
//Postcondition: If a record was in the Table with the specifiedkey, then
//that record has been removed; otherwise the table isunchanged.
template
void table::remove(int key) {
size_t index = hash(key);
if(!is_present(key)) {
return;
} else {
typename std::list::iterator it;
for(it = data[index].begin(); it != data[index].end(); ++it){
if(it -> key == key){
data[index].erase(it);
break;
}
}
}
}
//Postcondition: The return value is true if there is a recordin the
//Table with the specified key. Otherwise, the return value isfalse.
template
bool table::is_present(int key) const {
size_t index = hash(key);
typename std::list::const_iterator it;
for(it = data[index].begin(); it != data[index].end(); ++it){
if(it -> key == key)
return true;
}
return false;
}
template
RecordType table::get_record (int key) const {
return key;
}
//Postcondition: Return the total number of records in the
//Table.
template
size_t table::size( ) const {
return get_record;
}
template
std::ostream& operator << (std::ostream& output,const table& t) {
typename table:: iterator it;
for(it = t.begin (); it != t.end(); ++it) {
output << *it < }
return output;
}
template
size_t table::hash(int key) const {
return (key % NUM_BUCKETS);
}
//Postcondition: If a record is in the Table with the specifiedkey, then
//found is true and location is set to an iterator access therecord.
//Otherwise found is false and the result contains garbage.
template
void table::find_location(int key, bool& found, typenamestd::list::iterator& location) {
size_t index = hash(key);
if(is_present(key)){
found = true;
RecordType& result;
for(location = data[index].begin(); location != data[index].end();++location) {
if(location -> key == key)
result = *location;
return;
}
} else {
found = false;
}
}
=================================================================
test_table2.cpp
#include “table2.h”
#include
#include
#include
using namespace std;
using namespace main_savitch_12B;
// Struct definition for the test_record_type, which has a key,string
// and a double.
typedef struct struct_test_record_type
{
int key;
string s;
double data;
} test_record_type;
// postcondition: r has been displayed on out
ostream& operator << (ostream& out, consttest_record_type& r);
int main ()
{
table t;
test_record_type item1 {34, “abc”, 26.1};
t.insert (item1);
test_record_type item2 {34, “hhh”, 127};
t.insert (item2);
test_record_type item3 {44, “xyz”, -14.5};
t.insert (item3);
test_record_type item4 {28, “bcd”, 0.1};
t.insert (item4);
test_record_type item5 {8, “cde”, -5.66};
t.insert (item5);
test_record_type item6 {17, “efg”, 2.5};
t.insert (item6);
test_record_type item7 {87, “fgh”, 78.3};
t.insert (item7);
test_record_type item8 {1, “ghi”, 333.78};
t.insert (item8);
test_record_type item9 {6, “hij”, 34.22};
t.insert (item9);
test_record_type item10 {84, “ijk”, 116};
t.insert (item10);
cout << t << endl;
t.remove (44);
cout << t << endl;
t.remove (17);
cout << t << endl;
t.remove (99);
cout << t << endl;
return EXIT_SUCCESS;
}
ostream& operator << (ostream& out, consttest_record_type& r)
{
out << “key: ” << r.key << ” s: ” << r.s<< ” data: ” << r.data << endl;
return out;
}
Expert Answer
Answer to I keep getting an ambiguous overload error for my program, can someone please help me fix it? The file I had to implemen… . . .
OR

