0

i have this complex error respectively it looks complex. I think I have a mistake at may transfer parameters. But I don't know what is the mistake. At the web I found this syntax and dont understand waht I must write corctly at this case.

Thank you everyone for your help and sorry for may bad englisch. this ist the erormessage: undefined reference to drawfield(std::vector<std::vector<char, std::allocator >, std::allocator<std::vector<char, std::allocator > > >)

and that is may litle code:

#include <iostream>
#include <vector>
void drawfield(std::vector <std::vector <char>>);
void round (int);
int roundnumber=1;
int main()
{
 std::vector <std::vector <char>> playfield 
 { {'1','2','3'},{'4','5','6'},{'7','8','9'} };
 drawfield (playfield);
 int round (roundnumber);
 return 0;
system("puase");

}

void round(int &roundumber)
{
    roundnumber++;
}
void playerinput(std::vector<std::vector<char>> &playfield)
{
    playfield[3][3];
    int input=0;
    int ir=0;   //input row
    int ic=0; //input colum
    std::cout<< "wähle ein freies Feld von 1-9 in dem du setzten Möchtest:";
    std::cin>> input;
    ir=input / 3; //calculation of the row
    ic=input % 3;   // calculation of the column
    
    if(roundnumber%2 ==0)
    {
        playfield[ir][ic]='X';
    }
    else 
    {
        playfield[ir][ic]='O';
    }
}

void drawfield( const std::vector<std::vector <char>> &playfield )
{
    playfield[3][3];
        for (int r = 0; playfield.size(); r++)
        {   
            for (int c = 0; c<playfield[r].size(); c++)
            {
                std::cout <<" " << playfield[r][c] << " ";
            }
                std::cout<<std::endl;
        }   
}

1 Answers1

1

Look at this (the declaration)

void drawfield(std::vector <std::vector <char>>);

Now look at this (the definition)

void drawfield( const std::vector<std::vector <char>> &playfield )

See the difference? That's where the problem is, they should be the same.

BTW this is wrong (both times)

playfield[3][3];

Just remove it.

john
  • 85,011
  • 4
  • 57
  • 81