.....xx........
....x..xx......
....x....xxxx..
...x........xxx
..x............
...x........xx.
...x..xxx...x.x
...x..x..x.x...
...xxxx...x....
...............
into a two dimensional vector, which I was able to do. Now however, I am supposed to ask the user for a starting point (which I did), and then fill the "." with"x" (using a recursive function) as long as I stay inside the borders of the "x"s. Like this...
.....xx........
....xxxxx......
....xxxxxxxxx..
...xxxxxxxxxxxx
..xxxxxxxxxxxxx
...xxxxxxxxxxx.
...xxxxxx...x.x
...xxxx..x.x...
...xxxx...x....
...............
Here is my code so far...
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void input(int &pixelrow, int &pixelcolumn);
void AreaFill(vector<vector<char> >&picture, int pixelrow, int pixelcolumn);
void display(vector<vector<char> >picture);
int main()
{
ifstream infile("picture.txt");
if(!infile)
{
cout<<"File could not be opened."<<endl;
exit(1);
}
vector<vector<char> >picture(1);
string line;
int rows=0, pixelrow, pixelcolumn;
while(getline(infile, line))
{
picture[rows].resize(line.size());
for(int x=0; x<line.size(); x++)
picture[rows][x]=line[x];
picture.resize(picture.size()+1);
rows++;
}
display(picture);
input(pixelrow, pixelcolumn);
AreaFill(picture, pixelrow, pixelcolumn);
display(picture);
}
void input(int &pixelrow, int &pixelcolumn)
{
cout<<"Enter starting pixel location"<<endl;
cin>>pixelrow>>pixelcolumn;
}
void AreaFill(vector<vector<char> >picture, int pixelrow, int pixelcolumn)
{
if(pixelrow>0 && pixelcolumn>0 && pixelcolumn<picture[0].size() && pixelrow<picture.size() && picture[pixelrow][pixelcolumn]!='x')
picture[pixelrow][pixelcolumn]='x';
AreaFill(picture, pixelrow-1, pixelcolumn);
AreaFill(picture, pixelrow, pixelcolumn+1);
AreaFill(picture, pixelrow+1, pixelcolumn);
AreaFill(picture, pixelrow, pixelcolumn-1);
}
void display(vector<vector<char> >picture)
{
for(int x=0; x<picture.size(); x++)
{
for(int y=0; y<picture[x].size(); y++)
cout<<picture[x][y];
cout<<endl;
}
}
I get 4 errors, one for each time that I call the AreaFill function (my recursive function). The error says...
"call of overloaded `AreaFill(std::vector<std::vector<char, std::allocator<char> >, std::allocator<std::vector<char, std::allocator<char> > > >&, int, int&)' is ambiguous"
This is my first program using recursive functions so I am not sure if I am approaching this right. Any help would be greatly appreciated. Thanks.

New Topic/Question
Reply




MultiQuote




|