Passing a 2D array of unknown size into a function in C++ -


i'm trying input 2d array function. don't know number of rows or columns array , loaded c++ via cimg. have:

// main function: int main() {     int rows, columns;     float summation;     cimg<unsigned char> prettypicture("prettypicture.pgm");     rows = prettypicture.height();     columns = prettypicture.width();      summation = sum(prettypicture[][], rows, columns); }  // summation function: float sum(int **picture, int rows, int column) { ... // there code here don think important. } 

i pass array summation function , i'm aware should using pointers in way, i'm not sure how this. appreciated.

thank you

(sorry being noob)

try this:

summation = sum(prettypicture.data(), rows, columns); 

and make sum function this:

float sum(char* picture, int rows, int column) ... 

you need pass in data (if want pointer data) because that's cimg provides. it's pointer character because that's kind of cimg have; , it's char*, not char**, because that's data provides.

you didn't show inside of sum function, wonder if might pass in cimg instead of data, , call member function atxy takes position. hard without seeing more.

for more information on data , other member functions of cimg, see http://cimg.eu/reference/structcimg__library_1_1cimg.html .


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -