This question already has answers here:
Access Item in Nested Structure in C
                                
                                    (2个答案)
                                
                        
                                3年前关闭。
            
                    
typedef struct _imat {
 int **m_mat;
 int rows, cols;
} intMat;

typedef struct _banker {
 intMat A;
 intMat M;
 int *C;
 int numRes;
 int numProcs;
 } banker;

int main(int argc, char* argv[])
{
  banker *b,c;
  b = &c;
 matInit((*b).A,(*b).numProcs,(*b).numRes);
}


我正在尝试在intMat A结构中访问_banker,但出现错误:

"expected ‘struct intMat *’ but argument is of type ‘intMat’ void matInit(intMat *mat,int rows, int cols){"

最佳答案

(*b).A的类型为intMat

但是matInit期望的是intMat *

因此,将(*b).A替换为&(*b).A,因为“&”将使其成为指针

10-08 04:09