Connecting Tech Pros Worldwide Help | Site Map

incompatible types in assignment?

Member
 
Join Date: May 2007
Posts: 119
#1: Aug 11 '09
I am getting a "error: incompatible types in assignment" error and cant figure out why? I am trying to set lastRow to row at the end of the code snippet.

Expand|Select|Wrap|Line Numbers
  1.     int row[height][3];
  2.     int lastRow[height][3];
  3.  
  4.     size_t rowIdx, idx = 0;
  5.     int cRow = startX;
  6.     for (idx = startX ; idx < height*width; idx += width)
  7.     {
  8.       cRow = (idx/width);
  9.  
  10.       row[cRow][0] = redImg.data[idx]; 
  11.       row[cRow][1] = greenImg.data[idx] ;    
  12.       row[cRow][2] = blueImg.data[idx]; 
  13.  
  14.     }
  15.  
  16.     lastRow = row;
  17.  
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,158
#2: Aug 11 '09

re: incompatible types in assignment?


C/C++ does not support arithmetic operations on arrays including copying.

If this is C then use memcpy.

If this is C++ you should be using vectors not arrays (which do support copying).
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 828
#3: Aug 11 '09

re: incompatible types in assignment?


Another approach would be to have two generically named arrays plus two pointer-to-array variables called row and lastRow. Instead of copying the row array you could swap the pointer values.

However, working with a pointer to a two-dimensional array can be quite tricky. If you're interested in this approach you should first read Arrays Revealed.
Reply