Visual C ++ 15.7.6构造函数演绎指导问题 [英] Visual C++ 15.7.6 constructor deduction guide problem

查看:58
本文介绍了Visual C ++ 15.7.6构造函数演绎指导问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// In Visual C++ 15.7.6, constructor deduction guides work with simple constructors:
template<class t> struct class0 {class0(t) {}};
class0(char)->class0<char>;
int testclass0() noexcept {class0('x');}

// However, they seem broken in the case of templated constructors as follows:
template<class t> struct class1 {template<class u> class1(u) {}};
class1(char)->class1<char>;
int testclass1() noexcept {class1('x');}

// error C2672: 'class1': no matching overloaded function found
// error C2783: 'class1<t> class1(u)': could not deduce template argument for 't'

有什么建议吗?

推荐答案

首先测试这是否适用于其他编译器。如果这在多个其他编译器中成功,但在VC中失败则可能是VC错误。但是如果它在其他编译器中也失败了,那么很可能你的理解是不正确的。

Test if this works in other compilers first. If this succeeds in more than one of the other compilers, but fails in VC then it is possible that it is a VC bug. But if it fails in other compilers too, then it is quite possible that your understanding is incorrect.

如果你已经测试并且你认为它是一个bug,那么使用报告报告它从Visual Studio窗口右上角的"发送反馈"按钮中的"问题"选项,它位于"快速启动"栏的左侧。

If you have tested and you believe that it is a bug, then report it using the Report a Problem option from the Send Feedback button in the top right of the Visual Studio window, it is to the left of the Quick Launch bar.

作为一种解决方法,如果您创建了class1扣除指导模板?即。

As a workaround, what happens if you make the class1 deduction guide a template? I.e.

template<typename t>
class1(t) -> class1<t>;

这是否有效或失败?


这篇关于Visual C ++ 15.7.6构造函数演绎指导问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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