c++ - Visual Studio 2015 rc中从模板类派生的类的构造函数继承

标签 c++ templates inheritance constructor visual-studio-2015

根据msvs2015rc的page,新功能应该支持构造函数继承。是的,它适用于像这样的简单情况:

struct B { 
    B(int) {}
};
struct D : B {
    using B::B; // now we can create D object with B's constructor 
};

但是如果我尝试创建更复杂的示例:

template <class T>
struct B
{
    B(int) {} 
};

template <template <class> class C, class T>
struct D : C<T>
{
    using C<T>::C;
};

int main() {

    D<B,int> d(42);
    return 0;
}

我遇到编译器错误:

  • error C2039: 'C': is not a member of 'B<T>'
  • error C2873: 'C': symbol cannot be used in a using-declaration
  • error C2664: 'D<B,int>::D(D<B,int> &&)': cannot convert argument 1 from 'int' to 'const D<B,int> &'

当且仅当将模板模板类 C 重命名为 B 时,我才能消除这些错误:

template <template <class> class B, class T>
struct D : B<T>
{
    using B<T>::B;
};

我认为这是一个编译器错误,因为所有这些代码都用 gcc/clang 编译得很好。

有人对这个问题有其他看法吗?

最佳答案

这是 MSVC 中的一个错误,它也出现在他们在线提供的最新版本中。因此,请提交错误报告。相关讨论可参见 other所以问题。它包含标准的一些摘录,解释了它为什么应该起作用。

关于c++ - Visual Studio 2015 rc中从模板类派生的类的构造函数继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31232592/

相关文章:

c++ - Windows CE 内部构件,TEB(线程环境 block )

子类无法访问 C++ 公共(public)非虚拟基类方法

c# - 静态方法继承的正确替代方法是什么?

c# - 为什么我需要引用一个我没有直接使用的 dll?

c++ - 屏蔽对于阻止旁路攻击是否有效?

c++ - 实现 IDropTarget

c++ - 将 QString 转换为 float 给我错误

C++ "argument list for class template "迭代器“丢失”错误

WPF 模板错误 - "Provide value on ' System.Windows.Baml2006.TypeConverterMarkupExtension' 引发了异常。”

c++ - 确定比较中文字的有效类型