我真的不知道該怎麼辦。我看到的每個答案都有我不明白的語法。錯誤C2064使用<functional>和<bind>
錯誤:
Error 1 error C2064: term does not evaluate to a function taking 1 arguments
我使用哈希表的構造函數指針。有人建議我使用頭文件來解決我遇到的問題。它解決了錯誤,但我遇到了上述錯誤。
我的哈希表的聲明和構造函數如下:
#pragma once
#include "SLList.h"
template<typename Type> class HTable
{
public:
HTable(unsigned int numOfBuckets, std::function<unsigned int(const Type&)> hFunction);
~HTable();
HTable<Type>& operator=(const HTable<Type>& that);
HTable(const HTable<Type>& that);
void insert(const Type& v);
bool findAndRemove(const Type& v);
void clear();
int find(const Type& v) const;
private:
SLList<Type>* ht;
std::function<unsigned int(const Type&)> hFunct;
unsigned int numOfBuck;
};
template<typename Type>
HTable<Type>:: HTable(unsigned int numOfBuckets, std::function<unsigned int(const Type&)> hFunction)
{
ht = new SLList<Type>[numOfBuckets];
this->numOfBuck = numOfBuckets;
this->hFunct = hFunction;
}
Game.h(含表):
#pragma once
#include "stdafx.h"
#include "HTable.h"
#include "BST.h"
#include "DTSTimer.h"
using namespace std;
class Game
{
public:
Game(void);
virtual ~Game(void);
void refresh();
void input();
unsigned int xorHash(const string &s);
private:
string userInput;
DTSTimer timer;
BST<string> answers;
HTable<string> dictionary;
};
Game.cpp(我試圖在xorHash函數傳遞)
#include "Game.h"
Game::Game(void) : dictionary(2048, std::bind(&Game::xorHash, this))
{
}
Game::~Game(void)
{
}
void Game::refresh()
{
}
void Game::input()
{
}
unsigned int Game::xorHash(const string &s)
{
return 0;
}
在此先感謝。
這很好,如果它不需要是一個非靜態成員。否則,你想在OP嘗試時使用'function'和'bind'。 –