I am getting error C2297: '*' : illegal, right operand has type 'double *' in this piece of code:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double cx=0.5;
double**image_array;
image_array= new double*[5];
for (int i=0;i<5;i++)
{
image_array[i]= new double[5];
for(int j=0;j<5;j++)
{
image_array[i][j]=0;
}
}
for (int i=0;i<5;i++){
for(int j=0;j<5;j++)
{
int i=cx*image_array[i,j];
}
}
system("PAUSE");
return 0;
}
Can anyone tell the reason. Can't I multiply the double array with double type data? Or what 开发者_StackOverflow社区else can I do?
image_array[i,j]
doesn't do what you want. You need image_array[i][j]
instead.
There's a few problems with your code - cleaning up the formatting, the main problem is your attempt to index image_array[i,j]. Use image_array[i][j] - here's a working interpretation of your code fragment, with some modifications.
#include <iostream>
using namespace std;
int main()
{
double cx=0.5;
double**image_array;
image_array= new double*[5];
for (int i=0;i<5;i++) {
image_array[i]= new double[5];
for(int j=0;j<5;j++)
{
image_array[i][j]=i*5+j;
}
}
for (int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
double d=cx*image_array[i][j];
cout << d << "-";
}
cout << endl;
}
//system("PAUSE");
return 0;
}
You can see sample output here: http://codepad.org/38r4CZ9W
精彩评论