我想创建一个将消息映射到默认处理器的编译时结构,但我的代码无法在msvs 2015 update2中编译。我认为这是编译器中的一个错误,因为代码非常有效并且使用gcc进行编译。下面你可以看到重现问题的最小例子
#include <tuple>
struct About;
struct PluginStub
{
static void About();
};
template<typename Sink>
class Processor
{
template<typename Call, typename Stub, Stub Pointer>
struct Method;
using Methods = std::tuple<Method<About, decltype(&PluginStub::About), &PluginStub::About>>;
};
这给出了这样的输出:
1> main.cpp(25): error C2440: 'specialization': cannot convert from 'void (__cdecl *)(void)' to 'unknown-type'
1> main.cpp(25): note: Context does not allow for disambiguation of overloaded function
1> main.cpp(26): note: see reference to class template instantiation 'Processor<Sink>' being compiled
问题:
答案 0 :(得分:2)
解决方法是使用std::decay
:
using Methods = std::tuple<Method<About,
typename std::decay<decltype(&PluginStub::About)>::type,
&PluginStub::About>>;
答案 1 :(得分:0)
如果处理器不是模板化的类,那么编译就好了。