Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ msvs 2015中的模板实例化错误_C++_Visual Studio - Fatal编程技术网

C++ msvs 2015中的模板实例化错误

C++ msvs 2015中的模板实例化错误,c++,visual-studio,C++,Visual Studio,我想创建一个编译时结构,将消息映射到默认处理器,但我的代码无法在msvs 2015 update2中编译。我认为这是编译器中的一个bug,因为代码是非常合法的,并且是用gcc编译的。下面您可以看到重现该问题的最小示例 #include <tuple> struct About; struct PluginStub { static void About(); }; template<typename Sink> class Processor { t

我想创建一个编译时结构,将消息映射到默认处理器,但我的代码无法在msvs 2015 update2中编译。我认为这是编译器中的一个bug,因为代码是非常合法的,并且是用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>>;
};
#包括
构造关于;
结构插件sub
{
关于()的静态空白;
};
模板
类处理器
{
模板
结构法;
使用方法=std::tuple;
};
这就产生了这样的输出:

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
1>main.cpp(25):错误C2440:“专门化”:无法从“void(u cdecl*)(void)”转换为“未知类型”
1> cpp(25):注意:上下文不允许消除重载函数的歧义
1> cpp(26):注意:请参阅对正在编译的类模板实例化“Processor”的引用
问题:

  • 关于MSV中的bug,我说得对吗
  • 如何解决这个问题

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

      using Methods = std::tuple<Method<About, 
                                 typename std::decay<decltype(&PluginStub::About)>::type, 
                                 &PluginStub::About>>;
      
      使用方法=std::tuple;
      
    • 事实上,这是一个错误。我创造了一张票
    • 解决此错误的另一种方法是移动 方法定义超出类处理器范围

    • p.S如果处理器不是模板类,那么一切都可以编译。

      您能详细说明为什么这会有帮助吗?@sliser当然,作为第二个参数,您需要函数指针的类型。很可能在vc++的
      decltype
      中附加了字符串,这就是
      std::decay
      的作用。@Cody Gray。在同一模板中