in c++ I have
vector > table;
How can I resize vector so that it has 3 rows and 4 columns, all zeros?
Someth
Don't! You'll have complex code and rubbish memory locality.
Instead have a vector of twelve integers, wrapped by a class that converts 2D indices into 1D indices.
template
struct matrix
{
matrix(unsigned m, unsigned n)
: m(m)
, n(n)
, vs(m*n)
{}
T& operator()(unsigned i, unsigned j)
{
return vs[i + m * j];
}
private:
unsigned m;
unsigned n;
std::vector vs;
};
int main()
{
matrix m(3, 4); // <-- there's your initialisation
m(1, 1) = 3;
}