简体   繁体   English

如何在struct的3维指针中访问指针数组

[英]How to access the pointer array inside the 3 dimentional pointer of struct

I have these structs declared : 我声明了这些结构:

typedef struct
{
  double* weight;
  char *etiquette;

  double active;
}Neuron;

typedef struct
{
  Neuron **grid;
  Neuron *capteur;
  double alpha;
  int rv;
}SOM;

and then somewhere in my program I have a pointer to the second structure 然后在程序的某个地方,我有一个指向第二种结构的指针

SOM *net;

then I want to access the *weight variable from net. 那么我想从网上访问* weight变量。 I can access it with 我可以用

net->capteur->weight;

but net->grid[0][0]->weight has errors. 但是net->grid[0][0]->weight出错。 Then I use net->grid[0][0].weight and it compiles but gives me a segmentaion fault. 然后,我使用net->grid[0][0].weight编译,但出现了段错误。 What is wrong with net->capteur->weight; net->capteur->weight;怎么了net->capteur->weight; statement and how can I fix it? 声明,我该如何解决?

grid and weight are pointer. 网格和权重是指针。 Have you initialize it? 你初始化了吗? if you want to read weight value you should do: *(net->grid[0][0].weight) 如果要读取重量值,则应该执行以下操作:*(net-> grid [0] [0] .weight)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM