Constructor inheritance for class derived from template class in visual studio 2015 rc

微笑、不失礼 提交于 2019-12-13 02:13:59

问题


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-declaration
  • error 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!