1

is it at all possible in a reasonable way without hacks to define the size of an object array in a class without making the array size static. eg.

class Byte_Buffer
{
    Byte_Buffer(uint16_t bs) : buf_size(bs) {}

    const uint16_t buf_size;

    uint8_t storage[ buf_size ]; 
}; 
ascripter
  • 5,665
  • 12
  • 45
  • 68
joe blogs
  • 142
  • 4
  • 16

1 Answers1

1

template < int ARRAY_LEN > // you can even set to a default value here of C++'11

class MyClass {
int array[ARRAY_LEN]; // Don't need to alloc or dealloc in structure! Works like you imagine!
}

// Then you set the length of each object where you declare the object, e.g.

MyClass<1024> instance; // But only works for constant values, i.e. known to compiler

joe blogs
  • 142
  • 4
  • 16