I'm not very expert in programming with c++ so my question may appear a bit stupid, but I can't understand what I'm doing wrong.
I want to allocate a vector with the instruction
vector <short int> myvec(rowotot * coltot)
in order to represent a matrix.
Before proceeding, I want to verify if I have sufficient space to allocate my vector. If I use
try {
vector <short int> myvec(rowtot * coltot);
}
catch (bad_alloc& ba) {
cert << "ERROR: ";
cerr << ba.what() << endl;
}
and then I try to modify the elements of the vector, I can't because
myvec is not declared in this scope
How can I do the check on the memory before saving any value in the vector? I hope my question is clear.