根据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/