여기 여러 스레드를 읽었으며 그에 맞게 설정했다고 생각합니다. 나는 문제가 내가 *를 사용하고 있고, 과부하가되지 않는다고 생각한다 < < 어떻게 든 제대로 설정, 즉 매개 변수 정의가 잘못되었다. 문제는 컴파일되고 성공적으로 실행되므로 실수를하고있는 위치에 대한 단서가 없습니다.C++에서 오버로드 << 연산자를 호출 할 수 없습니다.
이전에 답변을 드렸지만 정말로 찾지 못해 죄송합니다.
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <list>
#include <exception>
using namespace std; //Allows us to not prepend std:: to many things.
template<class t>
class HashingTable
{
public:
HashingTable();
HashingTable(int size);
void insert(const char *x);
private:
int x = 0;
vector<list<const char *>> hashedLists;
int currentSize;
int hash(const char * key);
friend std::ostream& operator << (std::ostream & os, const HashingTable<t>);
};
template<class t> std::ostream& operator<< (ostream & os, const HashingTable<t> &ht)
{
const int listSize = ht.size();
for (unsigned int i = 0; i < listSize; i++)
{
list<const char *> searchList = ht[i];
for (std::list<const char *>::const_iterator si = std::next(searchList.begin(), listSizeLimit); si != searchList.end(); ++si) //for each value in hashed list.
cout << *si << " ";
}
return os;
};
template<class t>
int HashingTable<t>::hash(const char * key) {
return key[0] - 'A';
};
template<class t>
HashingTable<t>::HashingTable(int size)
{
hashedLists.resize(size);
};
template<class t>
HashingTable<t>::HashingTable()
{
hashedLists.resize(0);
};
template<class t>
void HashingTable<t>::insert(const char *x) {
//string tempStr(x);
unsigned int hashVal = hash(x);
if (hashedLists.size() < (hashVal + 1)) //if the number of lists in the current vector is less than the resize value then...
hashedLists.resize(hashVal + 1); //resize the hashedLists vector
list<const char *> iList = hashedLists[hashVal];
if (std::find(iList.begin(), iList.end(), x) == iList.end())
{
iList.push_back(x);
hashedLists[hashVal] = iList;
}
currentSize++;
};
int main() /* A sample main program */
{
HashingTable<char*>* mht;
char* Names[25] = { "AB", "AC", "AE", "AZ",
"BA","BM", "BJ", "BZ",
"CA", "CX", "CZ", "CZZ",
"EJ", "EP", "EF", "ES",
"QW", "QE", "QR", "QD",
"SA", "SD", "SF", "SS", "SJ" };
int i;
mht = new HashingTable<char*>(0);
for (i = 0; i < 25; i++)
(*mht).insert(Names[i]);
cout << "Printing the hash table after inserting...." << endl;
cout << *mht;
cout << endl;
return 0;
}
감사 인사. 에서는
"발췌 문장"이 없습니다. [MCVE]를 선물하십시오. –
코드에서 수행중인 유일한 다른 작업은 배열을로드하는 것입니다. 나는 그것을 추가했다. 감사. – thePetester
이것은 완전한 코드가 아닙니다. 위의 주석에있는 링크를 읽고 고쳐주십시오. 리팩토링하여 모든 코드를 포함하는 단일 파일을 생성하고 모든 포함 및 현재 표시하지 않는 'using namespace std'등을 표시합니다. 우리는 여러분이 보여준 코드를 복사하여 편집기에 붙여 넣고 컴파일 할 수 있어야합니다. 그 때까지 대답하려고 노력하는 것은 시간 낭비입니다. –