Pergunta

I need some help with C++ templates.

The following lines are given:

  Array < int, 4, 7 > something1;

  Array < char, 3, 'F' > something2;

I have to write a template for this, and I tried something like:

template < typename T1, int a1, typename T2 >

class Array
{

.....

};

But I am pretty sure this won't be the correct way, I'm not really familiar with templates yet. I can't figure out how to handle this, because when creating "something1", the third parameter is an integer, and at "something2" the third parameter is a character. What should be the correct solution?

Foi útil?

Solução

Template parameters can be types or non-types. In the realm of non-types, integrals are commonly used. Both char and int are integral types.

template <typename T1, int A1, char C1>
class Array 
{
  // ...
};
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top