msvs 2015 中的模板实例化错误 [英] Template instantiation error in msvs 2015

查看:32
本文介绍了msvs 2015 中的模板实例化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个编译时结构,将消息映射到默认处理器,但我的代码无法在 msvs 2015 update2 中编译.我认为这是编译器中的一个错误,因为代码非常合法并且可以使用 gcc 进行编译.您可以在下面看到重现问题的最小示例

I want to create a compile time structure that maps messages to default processors, but my code fails to compile in msvs 2015 update2. I think it's a bug in the compilator as a code is quite legimate and compiles with gcc. Below you can see minimal example reproducing the problem

#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

问题:

  • 我对 msvs 中的错误是否正确?
  • 如何解决这个问题?

推荐答案

一种解决方法是使用 std::decay:

A workaround would be to use std::decay:

using Methods = std::tuple<Method<About, 
                           typename std::decay<decltype(&PluginStub::About)>::type, 
                           &PluginStub::About>>;

这篇关于msvs 2015 中的模板实例化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆