Programming and software design is a constant "choice of one thing over another". If you REALLY can't afford using std::vector
, and you need to expose data to the client-code using your class, then so be it. Document why it is so, and make sure that it's reviewed over time - it may be that when your new model of hardware that has 8MB of RAM instead of 2MB will be able to use the extra 4 bytes that a vector
takes over your plain pointer.
Or write an accessor function:
int& Foo::operator[](int pos)
{
// Add checks here to ensure `pos` is in range?
return data[pos];
}
Now you don't have to return the pointer at all...