Reputation: 27
I have several structures, and I keep getting a warning message. I've been trying for several hours to kick it out, but I can't. I would really appreciate the help.
This is the Student struct in the Student.h
header:
#ifndef __STUDENT_H__
#define __STUDENT_H__
#include "Teacher.h"
#include "ClassRoom.h"
struct Teacher;
struct ClassRoom;
typedef struct {
char * name;
struct ClassRoom *myClassRoom;
struct Teacher *myTeachers[3];
} Student;
void setTeacherDynamic(struct Teacher *t, struct Teacher* tt);
and this is the Student.c
source code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Teacher.h"
#include "Student.h"
struct Teacher;
void setTeacherDynamic(Teacher *t, Teacher* tt)
{
strcpy(t->name, tt->name);
t->myClass = NULL;
}
The warning message is:
The problem is with the function setTeacherDynamic(), and I don't know how to fix it.
The Teacher
struct:
and this is when I'm calling to the function, also in Student.c
Upvotes: 0
Views: 158
Reputation: 409176
You have multiple problems:
The first is that since you have forward declarations in Student.h
you don't need to include Teacher.h
or ClassRoom.h
. And in the source file Student.c
you can remove the forward declaration you have.
The second problem is that you don't actually have a struct Teacher
. You have a Teacher
type-alias for an anonymous structure. You should declare the actual structure for the forward declarations to work:
typedef struct Teacher { ... } Teacher;
You should do these changes for all your source and header files.
Upvotes: 1