mercredi 23 août 2017

Template value from class declaration in constructor definition

I use template to deduce required static array length. Header file looks like:

template<uint8_t LENGTH>
class Foo
{
   int array[LENGTH];
   Foo();
}

I want to use LENGTH value in constructor definition in cpp file, somewhat similiar to:

Foo::Foo()
{
   for(uint8_t i = 0; i < LENGTH; i++)
   {
      //do_stuff
   }
}

So far I've done this by assigning LENGTH value to another variable in header file. How can I do this?

Aucun commentaire:

Enregistrer un commentaire