V
V
vvafree2016-10-04 09:54:34
Programming
vvafree, 2016-10-04 09:54:34

Two-dimensional array in a structure, how to use it correctly?

I can not understand.
The code is like this. Our function should return 3 arrays. To implement this, I decided to use structures.

struct hsv{
   double h_buf;
   double s_buf;
   double v_buf;
};

hsv rgb2hsv(struct hsv img, unsigned char y, unsigned char x){
 //Размеры массивов мы получаем в функции
 img.h_buf[y][x];
 img.s_buf[y][x];
 img.v_buf[y][x];
 
 for(int i = 0; i < x; i++)
      for(int j=0; j < y; j++)
          {
          img.h_buf[j][i] = 1;
          img.s_buf[j][i] = 1;
          img.v_buf[j][i] = 1;
          }
  return img; 
}

Throws an error on img.h_buf[y][x] - the expression must have the type of an object pointer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RPG, 2016-10-04
@vvafree

That's how the compiler tells you. h_buf should be double**, but yours is just double. And don't forget about memory allocation, see examples of how to work with arrays in C++ correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question