Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Матрицы
Форум на CrossPlatform.RU > Разработка > С\С++
PunX
Здравствуйте, необходимо реализовать умножение уматриц делаю следующим образом:
matrix.h
void submatr(double** a, double** b, double** c, int row, int col,int N){
    for(int i=0; i<row;i++)
        for(int j=0;j<col;j++)
        {
        c[i][j]=0;
        for(int k=0;k<N;k++)
            c[i][j]+=(a[i][k]*b[k][j]);
    }
}

main.cpp
double a[3][4]={{1,1,1,1},{1,1,1,1},{1,1,1,1}};
double b[4][3]={{1,1,1},{1,1,1},{1,1,1}};
double c[3][3];
submatr(a,b,c,3,3);

и получаю ошибку:
error: cannot convert 'double (*)[4]' to 'double**' for argument '1' to 'void submatr(double**, double**, double**, int, int, int)'
где и что я неправильно делаю?
kibsoft
Вот зугуглил:
Цитата
double myArray[3][4] = { { 1.234, 3.567, 8.90, 0.123 }, { ... }, { ... } };

double * ptrs[3] = { &myArray[0], &myArray[1], &myArray[2] };

double ** ptr2ptr = &ptrs[0];

// call function
func(ptr2ptr, 3, 4); // void func(double**, int, int);

Note, I passed the 3, 4, as additional arguments cause the calling function has *no* way to find the dimensions for the sample.


An easier way to define and pass the original array is like that

void func(double arr[][4], int outersize);

which can be called

func(myArray, 3);

Here the called function *knows* the dimension of the inner arrays (rows) but not the dimension of the outer array.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.