abraham_hilbert - 10 months ago 56

C++ Question

I have the following problem:

`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;

}

// ...

};

};

Unfortunately, the compiler yields an error for "

`A < T, N_i...>::B < Ts... > res{ /* ... */ };`

`class B`

`class A`

`operator[]`

`class B`

Many thanks in advance.

Answer Source

Should be enough add a `typename`

before `A<T, N_i...>`

and a `template`

before `B< Ts... >`

.

I mean

```
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;
}
// ...
};
}
```

P.s.: should work also with C++11; not only with C++14