从 'int' 到 int* [-fpermissive] 的无效转换

invalid conversion from 'int' to int* [-fpermissive]

之前我实现了这个并且它有效:

int *train_X = (int *)mxGetData(IN_a);// pointer to 6th argument matrix train_X 

for (int i = 0; i < 6; i++)
{
    for (int j = 0; j < 6; j++)
    {
        cout << train_X[6 * i + j] << endl;
    }
}

int sizeTrain_X1 = mxGetM(IN_a);
int sizeTrain_X2 = mxGetN(IN_a);

我什至可以通过以下方法检查我是否得到正确的尺寸,一切都很好。

cout <<"Training input NumOfCollum:\n"<< sizeTrain_X1 << endl;
cout << "Training input NumOfRows:\n"<<sizeTrain_X2 << endl;

但是当我用下面的初始化尝试我的整个程序时,我得到了一个编译错误:

for (int epoch = 0; epoch<training_epochs; epoch++)
{
    for (int i = 0; i<train_S; i++)
    {
        rbm.contrastive_divergence(train_X[i], learning_rate, k);
    }
}

错误信息如下:

RBM.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’: RBM.cpp:570:64: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive] RBM.cpp:81:6: error: initializing argument 1 of ‘void RBM::contrastive_divergence(int*, double, int)’ [-fpermissive] RBM.cpp:615:32: error: invalid types ‘int[int]’ for array subscript

train_X 是一个 int*。当您执行 train_X[i] 时,您现在会得到一个 intcontrastive_divergence() 虽然想要 int*。由于您无法将 int 转换为 int*,因此您会收到后续错误。您要么需要将 train_X[i] 的地址作为 &train_X[i] 传递,要么只传递 train_X