c++ - Help with type conversion error -
when try compile program, following error:
main.cpp: in function ‘int main()’: main.cpp:67: error: cannot convert ‘int (*)[(((long unsigned int)(((long int)mapsizey) - 1)) + 1u)]’ ‘int (*)[10]’ argument ‘3’ ‘void initializemap(int, int, int (*)[10])’ main.cpp:68: error: cannot convert ‘int (*)[(((long unsigned int)(((long int)mapsizey) - 1)) + 1u)]’ ‘int (*)[10]’ argument ‘3’ ‘void paintmap(int, int, int (*)[10])’ my code looks this:
#include <iostream> using namespace std; void initializemap(int mapsizex, int mapsizey, int map[][10]) { // map details: // 0 = # (wall) // 1 = space (free space) // 2 = x (player) for(int x = 0; x < mapsizex; x++) { map[x][0] = 0; } for(int y = 0; y < (mapsizey - 2); y++) { map[0][y] = 0; for(int x = 0; x < (mapsizex - 2); x++) { map[x][y] = 1; } map[mapsizex][y] = 0; } for(int x = 0; x < mapsizex; x++) { map[x][mapsizey - 1] = 0; } } void paintmap(int mapsizex, int mapsizey, int map[][10]) { for(int y = 0; y < mapsizey; y++) { for(int x = 0; x < mapsizex; x++) { switch(map[x][y]) { case 0: cout << "#"; break; case 1: cout << " "; break; case 2: cout << "x"; break; } cout << map[x][y]; } cout << endl; } } int main() { int mapsizex = 10; int mapsizey = 10; int map[mapsizex][mapsizey]; initializemap(mapsizex, mapsizey, map); paintmap(mapsizex, mapsizey, map); cout << endl << endl; return 0; } i've spent hour trying solve issue , twenty minutes searching solution. can of me out?
c++ not support variable-length arrays, map in code. however, compilers may support non-standard extension. however, won't compatible function expecting "standard" array.
if make mapsizex , mapsizey constants, should work.
Comments
Post a Comment