私は地図クラスを書きました:
typedef int (& func(const std::string &));
template <class t_child>
class map final
{
std::vector<t_child> m_table;
const func m_hasher;
public:
explicit map(const func hasher) : m_hasher(hasher) {}
map(const map ©) = delete;
~map();
map &operator=(const map&) = delete;
//***
};
しかし、エラーが発生します:
map.hpp:15: error: class ‘map<t_child>’ does not have any field named ‘m_hasher’
explicit map(const func hasher) : m_hasher(hasher) {}
^~~~~~~~
どうしましたか?なぜ存在しないのですか?
これは良い答えではないことは理解していますが、それが必要な場合は、簡単に機能させる方法を説明できます。
<functional>
関数ポインタの文法よりも覚えやすいので、私は通常このようなものに使用します。以下のコンパイルがあります。
#include <string>
#include <functional>
using func = std::function<int(std::string&)>;
template <class t_child>
class map final
{
std::vector<t_child> m_table;
const func m_hasher;
public:
explicit map(const func hasher) : m_hasher(hasher) {}
map(const map ©) = delete;
~map();
map &operator=(const map&) = delete;
//***
};
int main() {
return 0;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加