0

ここで何をすべきか本当にわかりません。私が調べたすべての回答には、理解できない構文があります。

エラー:

Error 1 error C2064: term does not evaluate to a function taking 1 arguments

ハッシュ テーブル コンストラクターで関数ポインターを使用しています。とヘッダーを使用して、私が抱えていた問題を解決することが提案されました。エラーは解決しましたが、上記のエラーが発生しました。

私のハッシュテーブル宣言とctorは次のとおりです:

#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;
}

前もって感謝します。

4

3 に答える 3

0

xorHash引数を1つ取るメソッドです。つまり、暗黙的にthisポインタもとります。

の外側のstaticメソッドまたはフリー関数にしclassます。

于 2013-11-09T20:02:15.383 に答える
0

渡したいハッシュ関数オブジェクトは、ハッシュする値を引数として取る必要があります。つまり、次のようなものをバインドしたいということです

std::bind(&Game::xorHash, this, std::placeholders::_1)

_1-bit は、引数がどこに行く必要があり、どの引数がそこに送信されるかを伝えるために必要です( std::bind()1 つしかないため、このコンテキストではどれがそれほど興味深いものではありません; 受信する関数をバインドしている場合は、より興味深いものになります)複数の引数)。

実際のメンバー関数を渡したいとは思わないことに注意してください: 通常、計算されたハッシュ値はオブジェクトの状態に依存しません。つまり、クラスxorHash()のメンバー関数を作成してこれを渡す方がよいでしょう。 : この方法では、パラメーターstaticも必要ありません。std::bind()

于 2013-11-09T20:02:27.030 に答える
0

バインドされていない関数引数のプレースホルダーが必要です。

std::bind(&Game::xorHash, this, std::placeholders::_1)

好みによると、ラムダの方が読みやすいかもしれません。

[this](const std::string & s){return xorHash(s);}

xorHash非静的メンバーである必要がある理由は私には明らかではありませんが。確かに、ハッシュはその入力のみに依存する必要がありますか?

于 2013-11-09T20:03:35.703 に答える