如何访问嵌套的struct对象

时间:2016-11-17 02:49:34

标签: c struct

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){"

1 个答案:

答案 0 :(得分:0)

(*b).A的类型为intMat

matInit期待intMat *

所以将(*b).A替换为&(*b).A,替换为“&”会使它成为指针