Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 嵌套类中的类实例化_C++_Templates_C++14_Variadic Templates - Fatal编程技术网

C++ 嵌套类中的类实例化

C++ 嵌套类中的类实例化,c++,templates,c++14,variadic-templates,C++,Templates,C++14,Variadic Templates,我有以下问题: template< typename T, size_t N, size_t... N_i > struct A { // nested class template< typename... Ts > class B { //... A<T, N_i...>::B< Ts... > operator[]( size_t i ) { A< T, N_i...

我有以下问题:

template< typename T, size_t N, size_t... N_i >
struct A
{
  // nested class
  template< typename... Ts >
  class B
  {
      //...

      A<T, N_i...>::B< Ts... > operator[]( size_t i )
      {
        A< T, N_i...>::B< Ts... > res{ /* ... */ };

        return res;
      }

      // ...
  };
};
模板
结构A
{
//嵌套类
模板
B类
{
//...
A::B运算符[](大小i)
{
A:Bres{/*…*/};
返回res;
}
// ...
};
};
不幸的是,编译器为“
A::Bres{/*…*/};
”产生了一个错误。有人知道我如何在
类B
的函数“
操作符[]
”中返回
类B
的实例化(其外部
类A
的模板参数不同)


非常感谢。

在返回类型的完整类型之前放置一个
typename
,可以修复您收到的错误。但是,不要将模板参数放在B之后,因为B总是引用类型的“当前”实例化

#include <stdio.h>
using namespace std;

template< typename T, size_t N, size_t... N_i >
struct A
{
  // nested class
  template< typename... Ts >
  class B
  {
      //...

      typename A<T, N_i...>::B operator[]( size_t i )
      {
        typename A< T, N_i...>::B res{ /* ... */ };

        return res;
      }

      // ...
  };
};
#包括
使用名称空间std;
模板
结构A
{
//嵌套类
模板
B类
{
//...
typename A::B运算符[](大小i)
{
类型名A::B res{/*…*/};
返回res;
}
// ...
};
};

a
之前添加
typename
模板在
B

我是说

template< typename T, size_t N, size_t... N_i >
struct A
{
  // nested class
  template< typename... Ts >
  class B
  {
      //...

      typename A<T, N_i...>::template B< Ts... > operator[]( size_t i )
      {
        typename A< T, N_i...>::template B< Ts... > res{ /* ... */ };

        return res;
      }

      // ...
  };
}
模板
结构A
{
//嵌套类
模板
B类
{
//...
typename A::模板B运算符[](大小i)
{
typename A::模板Bres{/*…*/};
返回res;
}
// ...
};
}

附言:也应使用C++11;不仅是C++14

对不起,我也不太明白;回答中的
操作符[]
返回什么?是
A::B
还是
A::B
?如果我理解正确,OP要求一个
A::B
再次抱歉:“将
名称空间
放在完整类型之前”是指“将
类型名
放在完整类型之前”吗?