问题
According to the page of msvs2015rc new features constructor inheritance should be supported. Yes, it works in simple cases like this:
struct B {
B(int) {}
};
struct D : B {
using B::B; // now we can create D object with B's constructor
};
But if I'll try to create more complex example:
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;
}
I've got compiler errors:
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> &'
I can eliminate these errors if and only if rename template template class C to B:
template <template <class> class B, class T>
struct D : B<T>
{
using B<T>::B;
};
I think this is a compiler bug because all of these codes well compiled with gcc/clang.
Do anybody has another opinion about this issue?
回答1:
It is a bug in the MSVC and it also appears in the latest version which they provide online. So, please, submit a bug report. Relevant discussion might be found in other SO question. It contains some excerpts from the standard which explain why it should work.
来源:https://stackoverflow.com/questions/31232592/constructor-inheritance-for-class-derived-from-template-class-in-visual-studio-2