class 的构造函数继承自 visual studio 2015 rc 中的模板 class
Constructor inheritance for class derived from template class in visual studio 2015 rc
根据 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> &'
当且仅当将模板模板 class C
重命名为 B
:
时,我才能消除这些错误
template <template <class> class B, class T>
struct D : B<T>
{
using B<T>::B;
};
我认为这是一个编译器错误,因为所有这些代码都使用 gcc/clang 编译得很好。
有人对这个问题有其他看法吗?
这是MSVC中的一个错误,并且在他们在线提供的最新版本中也出现了。所以,请提交错误报告。相关讨论可能会在 other SO question 中找到。它包含标准的一些摘录,解释了为什么它应该起作用。
根据 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> &'
当且仅当将模板模板 class C
重命名为 B
:
template <template <class> class B, class T>
struct D : B<T>
{
using B<T>::B;
};
我认为这是一个编译器错误,因为所有这些代码都使用 gcc/clang 编译得很好。
有人对这个问题有其他看法吗?
这是MSVC中的一个错误,并且在他们在线提供的最新版本中也出现了。所以,请提交错误报告。相关讨论可能会在 other SO question 中找到。它包含标准的一些摘录,解释了为什么它应该起作用。