【发布时间】:2012-02-28 13:30:10
【问题描述】:
我有一个数组,现在是静态的。这是我用它做的操作。 首先,我创建一个二维数组。然后我用循环填充它。然后我将它发送到函数,那里也使用了循环。 在这里,我想发布一些示例代码,这与我的相似。
bool picture[20][20]; //here's my array right now. Pretty ugly. Just for testing.
for (int y=0;y<Height;y++)
{
for (int x=0;x<Width;x++)
{
if (treshold<middle)
{
picture[x][y]=1;
}
else
{
picture[x][y]=0;
}
}
}
//Here's an example of filling an array
leftk = left(picture,widthk, heightk); //That's how I use a function
int left(int picture[200][200],int row,int col)
{
for (int x = 0; x <=row-1; x++)
{
for (int y = 0; y <=col-1 ;y++)
{
if (picture1[x][y]==1)
{
return x;
}
}
}
}
//And that's the function itself
所以在这里我需要将我的数组切换为动态数组。这就是我声明我的动态数组的方式
bool** picture=new bool*[size];
for(int i = 0; i < size; ++i)
picture[i] = new bool[size];
//size is just a variable.
至于静态声明的循环,一切都非常简单。将此数组作为参数发送给函数。
我已经设法创建了一个动态数组,这很简单。然后我用数字填充它。这里也没有问题。但我不明白,如何将数组发送到函数以及如何在那里使用它。 你能给我一个在函数中修改二维数组的例子吗? 对不起,这样的新手问题。希望有人会提供帮助。
顺便说一句,我认为类包装在这里会有点混乱。
【问题讨论】: