-1
class maps{

public:

    int rows;
    int cols;
    void size(char **lvl, char corner);

private:

};

void maps::size(char **lvl, char corner){
    for(int c=0; *lvl[c]!=corner; c++){
        cols=c;
    }
    for (int r=0; *lvl[r * cols + 1]!=corner; r++){
         cols=r;
    }
}

int main(int argc, char** argv) {
char w = 189; //wall
char e = 122; //entity
char y = 206; //you
char s = ' '; //space
char c = 188; //corner
control control_you;
maps map_level;
char lvl1[10][20]={{w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, c},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, e, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, w},
                   {w, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, y, w},
                   {c, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w, w}};
map_level.size(*lvl1, c);
    return 0;
 }

Bloc[Error] no matching function for call to 'maps::size(char [20], char&)

I don't know why it cant finds my function, can you help me? I don't know if I've done something wrong in the call of the function in my class or what, I'm desperate, please help me with that. Thank you.

David Yaw
  • 27,383
  • 4
  • 60
  • 93

1 Answers1

0

I would use std::vector<std::vector<char>> but doing it your way I would change the size() method like this:

void size(char* lvl, char corner){
    rows = 0;
    cols = 0;

    for (int c=0; lvl[c] != corner; c++){
        ++cols;
    }
    ++cols;  // count the corner 

    for (int r=0; lvl[r * cols] != corner; r++){
        ++rows;
    }
    ++rows;  // count the corner 
}

where cols and rows is are the same as the lvl1, including the corners. And hope there are corners at the right places.

And call it like this:

map_level.size((char*)lvl1, c);

Demo

How are multi-dimensional arrays formatted in memory?

Mihayl
  • 3,821
  • 2
  • 13
  • 32