Add a matrix of 2x2 into a vector in c++ -
i trying fill vector matrix of values in c++. i'm not self confident procedure (i don't know pointers , don't know if need here) trying this
int auxmat[gray.rows][gray.cols]; vector<int> collectionsum; collectionsum.push_back(auxmat);
when try compile receive error says
invalid arguments 'candidates are: void push_back(const int &)
can tell me wether it's possible do, how can solve it?
i read erasing cache memory, changing eclipse compiler, c++ version, don't think problem big.
you cannot push matrix vector. can preallocate memory vector (for speeding things up) use std::vector<>::assign
member function "copy" matrix vector:
vector<int> collectionsum(gray.rows * gray.cols); // reserve memory, faster collectionsum.assign(*auxmat, *auxmat + gray.rows * gray.cols);
this should pretty fast. otherwise, can push each individual element in loop.
edit
see may treat 2d array contiguous 1d array? technicalities regarding possible undefined behaviour (thanks @juanchopanza comment). believe code safe, due fact storage of matrix contiguous.
Comments
Post a Comment