【发布时间】:2018-01-25 20:39:30
【问题描述】:
struct Functor
{
public:
template <typename... argtypes>
Functor(std::function<void()> Function)
{
this->Function = Function;
}
~Functor() {}
void operator()() const
{
OutputDebugStringA("Hello there, General Kenobi");
Function();
}
private:
std::function<void()> Function;
};
void gtk()
{
OutputDebugStringA("What is happening to meeee");
}
Functor Draw = Functor(>k);
void foo() { Draw(); }
如何让 Functor 的 std::function 接受参数类型?
我尝试了以下方法:
Functor(std::function<void(argtypes...)> Function)
Functor Draw = Functor<void>(>k);
但编译器抱怨“不允许类型名”。
【问题讨论】:
-
请发minimal reproducible example 重现错误
-
@Praetorian 这是一个完整的例子。
-
不,不是。除了缺少标头包含和特定于操作系统的
OutputDebugStringA之外,发布的示例确实可以编译。您应该发布重现错误消息的版本。如果你问我认为你在问什么,答案是函数指针与std::function不同 -
不,它不是:完整的示例需要
main()和包含
标签: c++ c++11 templates std-function