C ++,继承模板嵌套类

时间:2010-12-27 21:54:09

标签: c++ templates inheritance

尝试在tensor_view中看到tensor_ref<A>::result

template<class A, class Range, class = void>
struct tensor_view
    : detail::tensor_ref<A>,
    const_tensor_view<A, Range, tensor_view<A, Range> >
{
    using detail::tensor_ref<A>::result;

...

template<class A>
struct tensor_ref<A, typename same_rank<A,N>::enable>
    : const_tensor_ref<A>
{
    template<class I>
    struct result {
        typedef typename traits<A>::reference type;
    };
  

错误:“struct tensor :: tensor_view&lt; ...

中没有名为”result“的类模板

是什么给出了?

4 个答案:

答案 0 :(得分:1)

不确定如何以你尝试的方式去做,或者如果有可能的话,但你应该能够通过这样做获得平等的东西:

// using detail::tensor_ref<A>::result;
template < typename I > struct result : detail::tensor_ref<I> {};

答案 1 :(得分:1)

这不起作用,isn't intended使其适用于C ++的任何进一步修订。

所以你不能使用声明 - 在使用它时使用普通的tensor_view::template result方式。

答案 2 :(得分:0)

你需要在它前面添加typename,因为它是一个依赖类型。

答案 3 :(得分:0)

我的猜测是,您在尝试实例化I时从未指定result<I>

例如:

detail::tensor_ref<A>::result;

应该是:

detail::tensor_ref<A>::result< /* Some type */ >;

那就是说,看起来你可以摆脱这条线:

template<class I>

因为在您提供的代码段中,I完全未使用。

相关问题