带有指向C中struct的指针的struct

时间:2015-12-13 16:46:26

标签: c pointers struct

我在头文件中有这段代码,我尝试在指向其他结构的指针内创建一个结构

#ifndef CAMERA_H
#define CAMERA_H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "azioni.h"

typedef struct Camera{
    int nrtCamera;
    char * nomeCliente;
    Camera * next;
    Azioni * headAzioni;
} camera;



#endif

我的问题是,当我尝试编译时,它给了我这个错误

In file included from Test.c:1:0:
camera.h:11:2: error: unknown type name ‘Camera’
  Camera * next;
  ^
camera.h:12:2: error: unknown type name ‘Azioni’
  Azioni * headAzioni;

我还有一个其他头文件,我声明结构Azioni,它给了我同样的问题。 怎么解决?

1 个答案:

答案 0 :(得分:1)

如果您对azioni的定义使用与camera相同的模式,即您将其定义为类似

的模式
struct Azioni {
  int some_field1;
  int some_field2;
  int etc;
} azioni;

然后您对Camera的定义可能是

typedef struct Camera{
  int nrtCamera;
  char * nomeCliente;
  struct Camera * next;
  struct Azioni * headAzioni;
} camera;

或者

typedef struct Camera{
  int nrtCamera;
  char * nomeCliente;
  struct Camera * next;
  azioni * headAzioni;
} camera;

祝你好运。