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

时间:2021-12-18 19:58:55

i have this block of code in a header file, i try to create a struct with inside a pointer to an other 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

my problem is that when i try to compile it gives me this error

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

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;

i have also an other header file where i declare the struct Azioni and it gives me the same problem. How can it be solved?

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

1 个解决方案

#1


1  

If you've use the same pattern for the definition of azioni as was used for camera, i.e. that you have it defined as something like

如果您使用相同的模式来定义azioni,就像用于相机一样,即你将它定义为像

struct Azioni {
  int some_field1;
  int some_field2;
  int etc;
} azioni;

then your definition for Camera could either be

那么您对Camera的定义可能是

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

or perhaps

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

Best of luck.

祝你好运。

#1


1  

If you've use the same pattern for the definition of azioni as was used for camera, i.e. that you have it defined as something like

如果您使用相同的模式来定义azioni,就像用于相机一样,即你将它定义为像

struct Azioni {
  int some_field1;
  int some_field2;
  int etc;
} azioni;

then your definition for Camera could either be

那么您对Camera的定义可能是

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

or perhaps

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

Best of luck.

祝你好运。