I have two alternatives:
class X{
int* x;
int size = ...;
void create() {
x = new int[size];
use();
delete [] x;
}
void use() {//use array}
};
or:
class X{
int size = ...;
void create(){
int x[size];
use(x);
}
void use(int arg[]) {//use arg}
};
which is better?
Option 3 is better, using
std::vector.Also, your second snippet is illegal, C++ doesn’t support VLAs.