【发布时间】:2015-07-05 16:36:19
【问题描述】:
根据 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-declarationerror 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 编译得很好。
有人对这个问题有其他看法吗?
【问题讨论】:
-
也许你在某处缺少
template或typename
标签: c++ templates inheritance constructor visual-studio-2015